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")
如果有人有更有效的解决方案,我很想听听,但这种方式对我来说效果很好。
推荐阅读
- javascript - 在 ES6 中使用默认值和扩展语法
- reactjs - 通知日期字段示例?更多文档
- symfony - 从默认 Symfony 3 翻译文件翻译教义查询
- opengl - 如何使用 glDebugMessageControl
- javascript - 如何将数据推送到位置为 [i] 的数组?
- botframework - 聊天机器人在 Microsoft Teams 人员列表中不可见
- android - Xamarin.Forms 带有软键盘或警报的 Android 沉浸式模式
- ios - JKCalendar 库不调用 tableview 委托方法
- c# - 来自不同机器的多个 .NET 客户端 SignalR
- assembly - CPU如何判断指令的顺序?