Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

How to initiate a Tor Browser 9.5 which uses the default Firefox to 68.9.0esr using GeckoDriver and Selenium through Python

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 system. But I'm facing an error as:

tor_firefoxESR

Code Block:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os

torexe = os.popen(r'C:UsersusernameDesktopTor BrowserBrowserTorBrowserToror.exe')
profile = FirefoxProfile(r'C:UsersusernameDesktopTor BrowserBrowserTorBrowserDataBrowserprofile.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:UsersusernameDesktopTor BrowserBrowserfirefox.exe'
driver = webdriver.Firefox(firefox_profile= profile, options = firefox_options, executable_path=r'C:WebDriversgeckodriver.exe')
driver.get("https://www.tiktok.com/")

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 Snapshot:

tor_firefox


Firefox Nightly Snapshot:

tor_firefoxNightly

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Note that although the code is in C# the same changes to the Tor browser and how it is launched should be applied.

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");

Important notes:

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

  • marionette.enabled: true

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...