【问题标题】:Using rvest to scrape from password protected website使用 rvest 从受密码保护的网站中抓取
【发布时间】:2018-06-17 15:52:12
【问题描述】:

一段时间以来,我一直在 HP EliteBook(运行 Windows 7)上成功使用 rvest 访问受密码保护的网站上的数据。

我成功运行的代码是:

加载所需的包

图书馆(rvest)

# Connect to confidential live report
URL <- url("http://username:password@urlofpasswordprotectedsite")
# Read in data
RawData <- read_html(URL)
# Identify the table
RawDataTable <- html_nodes(RawData, "table")
RawDataTable1 <- html_table(RawDataTable[1], fill = TRUE)
# Make data.frame
RawData <- as.data.frame(RawData)

但是现在尝试通过 R 抓取数据后,我遇到了以下错误:

Error in open.connection(x, "rb") : cannot open the connection

当我在 Mac 上工作时发生了这个错误,但我满足于坚持使用 HP 来运行分析。我可以毫无问题地加载以下内容:

htmlpage <- read_html("http://forecast.weather.gov/MapClick.php?lat=42.27925753000045&lon=-71.41616624299962#.V17UH-IrKHs")

这个错误是由于我的机器造成的,还是最近更新的 rvest 包可能会引发错误?

谢谢。

【问题讨论】:

    标签: rvest


    【解决方案1】:

    我设法解决了这个问题:

    html_session("http://username:password@urlofpasswordprotectedsite")
    

    代替:

    url("http://username:password@urlofpasswordprotectedsite")
    

    【讨论】:

      猜你喜欢
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多