我正在尝试从 R 中受密码保护的网站上抓取数据。四处阅读,似乎 httr 和 RCurl 包是使用密码身份验证进行抓取的最佳选择(我还研究了 XML 包)。
我试图抓取的网站如下(您需要一个免费帐户才能访问完整页面): http ://subscribers.footballguys.com/myfbg/myviewprojections.php?projector=2
这是我的两次尝试(用我的用户名替换“用户名”,用我的密码替换“密码”):
#This returns "Status: 200" without the data from the page:
library(httr)
GET("http://subscribers.footballguys.com/myfbg/myviewprojections.php?projector=2", authenticate("username", "password"))
#This returns the non-password protected preview (i.e., not the full page):
library(XML)
library(RCurl)
readHTMLTable(getURL("http://subscribers.footballguys.com/myfbg/myviewprojections.php?projector=2", userpwd = "username:password"))
我查看了其他相关帖子(下面的链接),但无法弄清楚如何将他们的答案应用于我的案例。
如何使用 R 从需要 cookie 的 SSL 页面下载压缩文件
如何在 R(https 链接)中抓取安全页面(使用 XML 包中的 readHTMLTable)?
http://www.inside-r.org/questions/how-scrape-data-password-protected-https-website-using-r-hold