当我做一些When抓取(使用for循环来废弃多个页面)时,有时,在从40页中抓取第35页之后,我有以下错误:
“open.connection中的错误(x,"rb"):达到了超时
有时我还会收到这样的信息:
“此外:警告消息:关闭未使用的连接3”
以下是我想澄清的事情清单:
1)我读过它可能需要显式地定义用户代理。我试过这样做:
read_html(curl('www.link.com', handle = curl::new_handle("useragent" = "Mozilla/5.0")))
但这并没有改变什么。
2)我注意到,当我打开VPN并改变位置时,有时我的抓取是没有任何错误的。我想知道为什么?
3)我也读过它可能依赖于代理。想要如何理解和为什么?
4)除了我所犯的错误之外,我还想了解这一警告,这是否可能是导致理解错误的线索:
警告消息:关闭未使用的连接3
这是否意味着,当我进行网络抓取时,我应该以某种方式调用一个函数来关闭连接?
我已经阅读了关于堆栈溢出的以下文章,但没有明确的解决方案:
Iterating rvest scrape function gives: "Error in open.connection(x, "rb") : Timeout was reached"
rvest Error in open.connection(x, "rb") : Timeout was reached
Error in open.connection(x, "rb") : Couldn't connect to server
发布于 2019-07-09 19:19:20
你试过这个吗?
https://stackoverflow.com/a/38463559
library(rvest)
url = "http://google.com"
download.file(url, destfile = "scrapedpage.html", quiet=TRUE)
content <- read_html("scrapedpage.html")
https://stackoverflow.com/questions/47800518
复制相似问题