Tor Browser with RSelenium in Linux/Windows
Question: 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 anybody get this to work? Perhaps you can share your
solution in either Windows / Linux.

    
    
    # library(devtools)
    # devtools::install_github("ropensci/RSelenium")
    library(RSelenium)
    
    RSelenium::checkForServer()
    RSelenium::startServer() 
    
    binaryExtension <- paste0(Sys.getenv('HOME'),"/Desktop/tor-browser_en-US/Browser/firefox")
    remDr <- remoteDriver(dir = binaryExtention)
    
    remDr$open()
    remDr$navigate("http://myexternalip.com/raw")
    remDr$quit()
    

The error `Error in callSuper(...) : object 'binaryExtention' not found` is
being returned.

For community reference, this Selenium code works in Windows using Python3:

    
    
    from bs4 import BeautifulSoup
    from selenium import webdriver
    from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
    from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
    
    from os.path import expanduser # Finds user's user name on Windows
    
    # Substring inserted to overcome r requirement in FirefoxBinary 
    binary = FirefoxBinary(r"%s\\Desktop\\Tor Browser\\Browser\\firefox.exe"  % (expanduser("~")))
    profile = FirefoxProfile(r"%s\\Desktop\\Tor Browser\\Browser\\TorBrowser\\Data\\Browser\\profile.default" % (expanduser("~")))
    
    driver = webdriver.Firefox(profile, binary)
    driver.get('http://myexternalip.com/raw')   
    html = driver.page_source
    soup = BeautifulSoup(html, "lxml") # lxml needed
    
    # driver.close()
    
    # line.strip('\n')
    "Current Tor IP: " + soup.text.strip('\n')
    
    # Based in part on
    # http://stackoverflow.com/questions/13960326/how-can-i-parse-a-website-using-selenium-and-beautifulsoup-in-python
    # http://stackoverflow.com/questions/34316878/python-selenium-binding-with-tor-browser
    # http://stackoverflow.com/questions/3367288/insert-variable-values-into-a-string-in-python
    


Answer: 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."
    

