如何通过Python通过GeckoDriver和Selenium初始化使用默认Firefox到68.9.0esr的Tor浏览器9.5 [英] How to initiate a Tor Browser 9.5 which uses the default Firefox to 68.9.0esr using GeckoDriver and Selenium through Python

查看:313
本文介绍了如何通过Python通过GeckoDriver和Selenium初始化使用默认Firefox到68.9.0esr的Tor浏览器9.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 Tor Browser 9.5 启动Tor浏览会话,该会话使用默认的 Firefox v68.9.0esr ,并使用GeckoDriver

I'm trying to initiate a tor browsing session through Tor Browser 9.5 which uses the default Firefox v68.9.0esr using GeckoDriver and Selenium through Python on a windows-10 system. But I'm facing an error as:

代码块:

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中使用各自的二进制文件工作.

Where as the same code block works through Firefox and Firefox Nightly using the respective binaries.

我需要任何其他设置吗?有人可以帮我吗?

Do I need any additional settings? Can someone help me out?

Firefox快照:

Firefox夜间快照:

推荐答案

我设法通过更新到v9.5.1并实现以下更改来解决此问题:

I managed to resolve this by updating to v9.5.1 and implementing the following changes:

请注意,尽管代码在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");

重要说明:

需要在 about:config 中更改以下TOR配置:

The following TOR configs need to be changed in about:config :

  • 木偶.已启用:是

marionette.port :设置为未使用的端口,并将此值设置为代码中的 firefoxDriverService.BrowserCommunicationPort .在我的示例中,该值设置为2828.

marionette.port: set to an unused port, and set this value to firefoxDriverService.BrowserCommunicationPort in your code. This was set to 2828 in my example.

这篇关于如何通过Python通过GeckoDriver和Selenium初始化使用默认Firefox到68.9.0esr的Tor浏览器9.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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