我正试图通过tor Browser 9.5启动tor浏览会话,它使用默认的Firefox v68.9.0esr在windows-10系统上通过Python使用GeckoDriver和Selenium。但我面临一个错误:
代码块:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os
torexe = os.popen(r'C:\Users\username\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile = FirefoxProfile(r'C:\Users\username\Desktop\Tor Browser\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)
profile.set_preference("network.proxy.socks_remote_dns", False)
profile.update_preferences()
firefox_options = webdriver.FirefoxOptions()
firefox_options.binary_location = r'C:\Users\username\Desktop\Tor Browser\Browser\firefox.exe'
driver = webdriver.Firefox(firefox_profile= profile, options = firefox_options, executable_path=r'C:\WebDrivers\geckodriver.exe')
driver.get("https://www.tiktok.com/")
其中,相同的代码块通过Firefox和Firefox每晚使用各自的二进制文件工作
我需要其他设置吗?有人能帮我吗
Firefox快照:
Firefox夜间快照:
我通过更新到v9.5.1并实施以下更改,成功地解决了这一问题:
请注意,尽管代码是C语言,但对Tor浏览器及其启动方式的相同更改也应适用
重要提示:
需要在关于:配置的中更改以下TOR配置:
木偶。已启用:真
木偶网.port:设置为未使用的端口,并在代码中将此值设置为firefoxDriverService.BrowserCommunicationPort。在我的示例中,该值设置为2828
注意:
我不确定这是否是确切的答案(因此,我非常感谢反馈)
解决方案:
我成功地向check-tor页面(https://check.torproject.org/)发送了一个get请求,它向我显示了一个未知的IP(另外,如果您在一段时间后重复该请求,则IP会有所不同)
基本上,我已经设置了chrome驱动程序来运行TOR。代码如下:
因为驱动程序没有处于headless模式,所以您可以自己检查生成的页面。它应该是:
祝贺您。此浏览器已配置为使用Tor。[IP信息]。但是,它似乎不是Tor浏览器。单击此处转到下载页面“
确保chromedriver.exe文件链接在路径上,或提供文件路径作为driver.Chrome()函数的参数
编辑:确保TOR浏览器在后台运行,感谢@Abhishek Rai指出这一点
相关问题 更多 >
编程相关推荐