pythonseleniumproxytorfirefox-profile

How to bypass Tor Network Settings confirmation popup using Selenium and Python


I'm attempting to automate the use of the Tor browser through selenium:

import time
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = '/Applications/TorBrowser.app/Contents/MacOS/firefox'
firefox_binary = FirefoxBinary(binary)
try:
    driver = webdriver.Firefox(firefox_binary="/Applications/Tor Browser.app/Contents/MacOS/firefox")
    driver.get("https://www.google.com/")
    time.sleep(3)
finally:
    driver.close()

I am trying to use Tor browser for scraping and everything works fine, but every time I run code you have to manually click connect button. How do I disable the confirmation screen or automatic its acceptance from within selenium? Tor browser


Solution

  • This browser configuration screen...

    connect_to_tor

    ... comes up because you haven't configured TOR Browser settings explicitly in your code block. So every time you execute your program, it initiates a new TOR browsing context without the proxy settings and assumes that you are running Tor Browser for the first time. Hence you will see the Tor Network Settings window on each run.


    Solution

    To get rid of the Tor Network Settings window, you need to configure the Tor Network Settings in your code block as follows:

    TOR_BROWSER


    References

    You can find a couple of detailed discussions in: