Linux/Windows 中带有 RSelenium 的 Tor 浏览器 [英] Tor Browser with RSelenium in Linux/Windows

查看:26
本文介绍了Linux/Windows 中带有 RSelenium 的 Tor 浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望通过我的 Linux 机器使用 RSelenium 和 Tor 来返回 Tor IP(使用 Firefox 作为 Tor 浏览器).这在 Python 中是可行的,但在 R 中遇到了麻烦.有人可以使用它吗?也许您可以在 Windows/Linux 中共享您的解决方案.

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

错误Error in callSuper(...) : object 'binaryExtention' not found 正在返回.

供社区参考,此 Selenium 代码可在使用 Python3 的 Windows 中运行:

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

推荐答案

类似下面的内容应该可以:

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)

更新:

这在 Windows 上对我有用.首先运行测试版:

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

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

接下来手动打开一个版本的 Tor 浏览器.

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

这篇关于Linux/Windows 中带有 RSelenium 的 Tor 浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆