【发布时间】:2022-02-09 10:03:44
【问题描述】:
我想通过 selenium 运行 TorBrowser。
我已经能够使用 tor 守护程序和 firefox 实例通过 selenium 使用 tor 网络。
我希望使用 TorBrowser 能够使用不同的 Tor 出口中继运行多个实例。 我知道可以通过将此行添加到 Browser/TorBrowser/Data/Browser/profile.default/user.js强>:
user_pref("network.proxy.socks_port", ChangeToTheDesiredPort1);
user_pref("extensions.torlauncher.control_port", ChangeToTheDesiredPort2);
这是我用来尝试通过 Selenium 启动 TorBrowser 的代码。我正在尝试一步一步地做这些事情,所以在这个测试中,我使用了一个没有个性化配置文件的全新 TorBrowser 存档:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
profile = FirefoxProfile("tor-browser_en-US/Browser/TorBrowser/Data/Browser/profile.default")
profile.set_preference('network.proxy.type', 1)
profile.set_preference('network.proxy.socks', '127.0.0.1')
profile.set_preference('network.proxy.socks_port', 9050)
options = FirefoxOptions()
options.profile = profile
binary = FirefoxBinary("tor-browser_en-US/Browser/start-tor-browser")
print "0"
driver = webdriver.Firefox(options=options, firefox_binary=binary)
print "1"
driver.get('https://check.torproject.org/')
一旦我尝试实例化 webdriver,我的脚本就会被阻止。 脚本的输出打印 0,从不打印 1,并且 TorBrowser 从不尝试连接到 https://check.torproject.org/
如果我替换
binary = FirefoxBinary("tor-browser_en-US/Browser/start-tor-browser")
通过
binary = FirefoxBinary("tor-browser_en-US/Browser/firefox")
脚本不再阻塞,TorBrowser 尝试联系https://check.torproject.org/,但 TorBrowser 从未连接到 Tor 网络,导致以下错误:
selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=proxyConnectFailure&u=https://check.torproject.org/&c=UTF-8&d=Firefox 配置为使用拒绝连接的代理服务器。
关于我的配置的一些信息(64 位):
- geckodriver 0.30.0
- TorBrowser 11.0.4
- Python 2.7.17
- Ubuntu 18.04.1
我已使示例脚本尽可能简单,但过去 2 天我测试了很多东西,但没有发现任何相关内容。
提前感谢您的回答。
【问题讨论】:
标签: python linux selenium tor-browser-bundle