r-登录后下载CSV文件



问题:

登录网站后,如何从以下链接下载CSV文件?

  • 网站:https://rotogrinders.com/
  • 链接:https://rotogrinders.com/grids/standard-projections-the-bat-x-3372510?site=draftkings/

到目前为止我所拥有的:

rg.headers <- c('User-Agent' = 'Mozilla/5.0')
rg.url <- "https://rotogrinders.com/"
rg.session <- html_session(rg.url, httr::add_headers(.headers=rg.headers))
rg.session <- rvest:::request_POST(rg.session, url = "https://rotogrinders.com/sign-in",
body = list("username"="*****",
"password"="*****"),
encode = 'json')
bat.p_redirect <- jump_to(rg.session, "https://rotogrinders.com/grids/standard-projections-the-bat-x-3372510?site=draftkings")

它让我登录并用下载为CSV按钮将我重定向到页面。我只是不知道从这里到哪里才能真正点击下载按钮并将.csv文件保存到我希望保存的地方。

我回答了自己的问题。下载为CSV按钮有自己的URL,所以我没有重定向到上面代码中的页面,而是重定向到按钮的URL并从那里抓取。

bat.p_redirect = jump_to(rg.session, "https://rotogrinders.com/grids/standard-projections-the-bat-x-3372510.csv?site=draftkings")$response$content
writeBin(bat.p_redirect, "C:/.../BAT.P.csv")

如果有人有更有效的解决方案,我很乐意听到,但这种方式对我来说很好

最新更新