Tor Browser with RSelenium in Linux/Windows

前端 未结 3 1420
攒了一身酷
攒了一身酷 2021-01-03 07:20

Looking to use RSelenium and Tor using my Linux machine to return the Tor IP (w/Firefox as Tor Browser). This is doable with Python, but having trouble with it in R. Can any

3条回答
  •  爱一瞬间的悲伤
    2021-01-03 08:10

    Caveat: I have not tested extensively, but it seems to work.

    Relying on some ideas from @Ashley72 but avoiding manual setups and copying (as well as now defunct functions from Rselenium needed for the solution from @jdharrison) and some ideas from https://indranilgayen.wordpress.com/2016/10/24/make-rselenium-work-with-r/ adjust the following profile options (I usually adjust a number of other options, but they do not seem relevant for the question):

    fprof <- makeFirefoxProfile(list(network.proxy.socks = "127.0.0.1", # for proxy settings specify the proxy host IP  
    network.proxy.socks_port = 9150L, # proxy port. Last character "L" for specifying integer is very important and if not specified it will not have any impact
    network.proxy.type = 1L, # 1 for manual and 2 for automatic configuration script. here also "L" is important    
    network.proxy.socks_version=5L, #ditto     
    network.proxy.socks_remote_dns=TRUE))
    

    Then you start the server as usual:

    rD <- rsDriver(port = 4445L, browser = "firefox", version = "latest", geckover = "latest", iedrver = NULL, phantomver = "2.1.1",
                   verbose = TRUE, check = TRUE, extraCapabilities = fprof) # works for selenium server: 3.3.1 and geckover: 0.15.0; Firefox: 52
    remDr <- rD[["client"]]
    remDr <- rD$client
    remDr$navigate("https://check.torproject.org/") # should confirm tor is setup
    remDr$navigate("http://whatismyip.org/") # should confirm tor is setup
    

    As you see, I have not made changes to the marionette option. I have no idea what the implications might be. Please comment.

    EDIT: the Tor Browser has to be up and running, it seems. Otherwise, the browser opened by Rselenium gives an error "proxy server refusing connection."

提交回复
热议问题