RSelenium behind proxy

匆匆过客 提交于 2019-12-12 07:40:29

问题


I am trying to use RSelenium. Here is what I am doing:

library(RSelenium)  
driver<- rsDriver(browser=c("chrome"))
remDr <- driver[["client"]]
remDr$open()

returns
$id
[1] NA

remDr$navigate("http://www.google.com")

(returns NULL)

remDr$getCurrentUrl()

returns empty list

I am thinking this disappointing result might be because I am behind corporate proxy.

How can I pass the http proxy to selenium browser?

Thank you


回答1:


You need to use extraCapabilities and set the proxy using the same

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")

And you can see that chrome now uses the proxy config




回答2:


I use RSelenium with Docker.

Here is mine option:

# connect to docker. 
# need to run in terminal (ctrl + alt + enter)
docker run -d -p  4445:4444 selenium/standalone-chrome:3.5.3
eCap <- list(chromeOptions = 
             list(args = list("--proxy-server=http://47.254.69.158:9999")))
remDr <- remoteDriver(remoteServerAddr = "localhost",
                  port = 4445L,
                  browserName = "chrome",
                  extraCapabilities = eCap)
remDr$open()
remDr$navigate("https://ipinfo.io/")
remDr$screenshot(display = TRUE)

So i got this this

If you still have troubles try to switch to other proxy and/or reload Docker.

Hope this will be usefull.



来源:https://stackoverflow.com/questions/50388282/rselenium-behind-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!