问题描述
我试图在我公司的代理后面运行 RSelenium,并且可以通过 GET 请求成功连接,但我无法正确运行 rsDriver() 函数。
set_config(use_proxy(url = "proxy.company.com",port = 80,username = "greg",password = "password"))
这样做后,我可以成功地运行 GET 请求,如果不使用 setconfig,我将无法执行该请求:
> GET("http://google.com")
Response [http://www.google.com/]
Date: 2021-02-09 18:30
Status: 200
我尝试使用 rsDriver 并在 Chrome 或 Firefox 上遇到连接问题:
cprof <- list(chromeOptions =
list(args = list("--proxy-server=proxy.company.com")))
driver <- rsDriver(browser = c("chrome"),extraCapabilities = cprof)
检查 Selenium 服务器版本: 开始:预下载 open.connection(con,"rb") 中的错误: 已达到超时:[www.googleapis.com] 操作在 10014 毫秒后超时,收到 0 个字节中的 0 个
我也尝试使用 Docker 客户端运行,但在尝试连接后收到一条奇怪的消息:
> remDr <- remoteDriver(remoteServerAddr = "127.0.0.1",port = 444L)
> remDr$open()
[1] "Connecting to Remote Server"
$id
[1] NA
我很困惑为什么无论我尝试什么都不能让它工作。任何指导都可以挽救生命。
谢谢
解决方法
这是一个很难搜索的问题,因为结果错误实际上只是 NA
。但是我发现了 this 关于如何在 RSelenium 中使用代理。基本上:
cprof <- list(chromeOptions =
list(args = list("--proxy-server=http://118.69.61.212:53281")))
driver<- rsDriver(browser=c("chrome"),extraCapabilities = cprof)
driver$client$navigate("http://ipinfo.io")
但您有一个硬编码的用户名和密码,出于安全原因,这似乎是 not possible to use with chrome。
但是,有人made a script可以使它工作(我没有尝试使用它,更不用说与 R 一起使用了,很想知道是否有人可以使它工作)。
无论如何,我遇到了所有相同的问题,所以我通过代理后面的 httr/rvest 发出请求,但对于通过 RSelenium 的请求,我使用 httr::reset_config()
停止使用代理,因此至少 RSelenium 工作(这不是这个问题的解决方案,只是一种妥协)。