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

后端 未结 1 566
梦毁少年i
梦毁少年i 2020-12-04 02:23

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 Pyt

相关标签:
1条回答
  • 2020-12-04 03:19

    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.

    0 讨论(0)
提交回复
热议问题