我正在尝试通过 Tor Browser 9.5 启动一个 Tor 浏览 session ,它使用默认的 Firefox v68.9.0esr 使用 GeckoDriver和 Selenium在 windows-10 上通过 Python系统。但我面临一个错误:
代码块:
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 Nightly 中使用各自的二进制文件。我需要任何其他设置吗?有人可以帮我吗?
火狐快照 :
Firefox 夜间快照 :
最佳答案
我设法通过更新到 v9.5.1 并实现以下更改来解决此问题:
请注意,尽管代码是在 C# 中,但应该应用对 Tor 浏览器及其启动方式的相同更改。
FirefoxProfile profile = new FirefoxProfile(profilePath);
profile.SetPreference("network.proxy.type", 1);
profile.SetPreference("network.proxy.socks", "127.0.0.1");
profile.SetPreference("network.proxy.socks_port", 9153);
profile.SetPreference("network.proxy.socks_remote_dns", false);
FirefoxDriverService firefoxDriverService = FirefoxDriverService.CreateDefaultService(geckoDriverDirectory);
firefoxDriverService.FirefoxBinaryPath = torPath;
firefoxDriverService.BrowserCommunicationPort = 2828;
var firefoxOptions = new FirefoxOptions
{
Profile = null,
LogLevel = FirefoxDriverLogLevel.Trace
};
firefoxOptions.AddArguments("-profile", profilePath);
FirefoxDriver driver = new FirefoxDriver(firefoxDriverService, firefoxOptions);
driver.Navigate().GoToUrl("https://www.google.com");
重要笔记:中需要更改以下 TOR 配置关于:配置 :
关于python - 如何通过 Python 使用 GeckoDriver 和 Selenium 启动使用默认 Firefox 到 68.9.0esr 的 Tor 浏览器 9.5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62666075/