Tôi đang cố gắng để xóa dữ liệu từ một trang web được bảo vệ bằng mật khẩu trong R. Đọc xung quanh, có vẻ như các gói httr và RCurl là các tùy chọn tốt nhất để cạo bằng xác thực mật khẩu (Tôi đã cũng đã xem xét gói XML).Cạo mật khẩu bảo vệ trang web trong R
Các trang web tôi đang cố gắng để cạo dưới (bạn cần có một tài khoản miễn phí để truy cập vào trang đầy đủ): http://subscribers.footballguys.com/myfbg/myviewprojections.php?projector=2
Dưới đây là hai nỗ lực của tôi (thay thế "username" với tên truy cập và "của tôi mật khẩu "với mật khẩu của tôi):
#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"))
Tôi đã xem các bài đăng có liên quan khác (liên kết bên dưới), nhưng không thể tìm ra cách áp dụng câu trả lời cho trường hợp của tôi.
How to use R to download a zipped file from a SSL page that requires cookies
How to webscrape secured pages in R (https links) (using readHTMLTable from XML package)?
Reading information from a password protected site
R - RCurl scrape data from a password-protected site
http://www.inside-r.org/questions/how-scrape-data-password-protected-https-website-using-r-hold
Điều này làm việc cho tôi. Tôi đã chỉnh sửa với đầu ra nội dung – jdharrison
Tuyệt vời! Tôi không nghĩ rằng nó dễ dàng hơn nhiều ... – Stefan
Tôi đã thử nghiệm cả hai câu trả lời và cả hai đều làm việc tuyệt vời.Tôi đã chọn cái này cho sự đơn giản của nó. – dadrivr