登录后下载 CSV 文件
Download CSV file after Login
问题:
如何在登录网站后从以下link下载CSV文件?
- 站点:https://rotogrinders.com/
- link: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")
如果有人有更有效的解决方案,我很想听听,但这种方式对我很有效。
问题:
如何在登录网站后从以下link下载CSV文件?
- 站点:https://rotogrinders.com/
- link: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")
如果有人有更有效的解决方案,我很想听听,但这种方式对我很有效。