Tor Browser with RSelenium in Linux/Windows

前端 未结 3 1395
攒了一身酷
攒了一身酷 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

    Something like the following should work:

    browserP <- paste0(Sys.getenv('HOME'),"/Desktop/tor-browser_en-US/Browser/firefox")
    jArg <- paste0("-Dwebdriver.firefox.bin='", browserP, "'")
    selServ <- RSelenium::startServer(javaargs = jArg)
    

    UPDATE:

    This worked for me on windows. Firstly run the beta version:

    checkForServer(update = TRUE, beta = TRUE, rename = FALSE)
    

    Next open a version of the tor browser manually.

    library(RSelenium)
    browserP <- "C:/Users/john/Desktop/Tor Browser/Browser/firefox.exe"
    jArg <- paste0("-Dwebdriver.firefox.bin=\"", browserP, "\"")
    pLoc <- "C:/Users/john/Desktop/Tor Browser/Browser/TorBrowser/Data/Browser/profile.meek-http-helper/"
    jArg <- c(jArg, paste0("-Dwebdriver.firefox.profile=\"", pLoc, "\""))
    selServ <- RSelenium::startServer(javaargs = jArg)
    
    remDr <- remoteDriver(extraCapabilities = list(marionette = TRUE))
    remDr$open()
    remDr$navigate("https://check.torproject.org/")
    
    > remDr$getTitle()
    [[1]]
    [1] "Congratulations. This browser is configured to use Tor."
    
    0 讨论(0)
  • 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."

    0 讨论(0)
  • 2021-01-03 08:15

    This works in MacOS Sierra.

    First you need to configure both the Firefox and Tor browser Manual Proxy.

    Go to your Preferences>Advanced>Network>Settings

    Set SOCKS Host: 127.0.0.1 Port:9150 Check -> on SOCKS v5 in the browser menu bar.

    You will also need to have Tor Browser open whilst running the R script in Rstudio ....otherwise you will get a message in the firefox browser "The proxy server is refusing connections"

    You will also need to copy the name of your firefox profile in the script profile-name

    Open Finder and got to /Users/username/Library/Application Support/Firefox/Profiles/profile-name

    My R test script

     require(RSelenium)
    
        fprof <- getFirefoxProfile("/Users/**username**/Library/Application\ Support/Firefox/Profiles/nfqudbv2.default-1484451212373",useBase=TRUE)
    
        remDrv <- remoteDriver( browserName = "firefox"
                                , extraCapabilities = fprof)
    
        remDrv$open()
        remDrv$navigate("https://check.torproject.org/")
    

    This will open an instance of the Firefox browser with the message "Congratulations. This browser is configured to use Tor."

    0 讨论(0)
提交回复
热议问题