Using Rselenium with firefox and socks5h

2019-05-30 04:53发布

问题:

I'm using the RSelenium package to connect to firefox, but I wish to do it via a socks proxy.

In Python, this is achievable using the webdriver package and setting the preferences of the FirefoxProfile, e.g. profile=webdriver.FirefoxProfile() profile.set_preference('network.proxy.socks', x.x.x.x) profile.set_preference('network.proxy.socks_port', ****) browser=webdriver.Firefox(profile)

However, I can't find how to try set the proxy to be a socks proxy, or to set the socks port in RSelenium. I've tried setting it using the RCurl options, as follows options(RCurlOptions = list(proxy = "socks5h://x.x.x.x:****")) but this gives me the following error message Error in function (type, msg, asError = TRUE) : Can't complete SOCKS5 connection to 0.0.0.0:0. (1) Has anyone successfully connected to Firefox using a socks proxy using R code?

I am using version 1.3.5 of RSelenium and version 28.0 of Firefox.

回答1:

Not tested but something like the following should work:

fprof <- makeFirefoxProfile(list(
  "network.proxy.socks" = "squid.home-server"
  , "network.proxy.socks_port" = 3128L
  , "network.proxy.type" = 1L
)
)
remDr <- remoteDriver(extraCapabilities = fprof)
remDr$open()