'Starting Tor with Selenium so that it reads the torrc configuration before starting
With the following code, on a Mac I start a Tor with Selenium and Python:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
import os
import time
binary = '/Applications/Tor Browser.app/Contents/MacOS/firefox'
# binary location
if os.path.exists(binary) is False:
raise ValueError("The binary path to Tor firefox does not exist.")
firefox_binary = FirefoxBinary(binary)
browser = None
def get_browser(binary=None, options=None):
global browser
# only one instance of a browser opens
if not browser:
browser = webdriver.Firefox(firefox_binary=binary, options=options)
return browser
browser = get_browser(binary=firefox_binary)
time.sleep(20)
browser.get("http://stackoverflow.com")
time.sleep(10)
html = browser.page_source
print(html)
This was ok until I found the launched Tor (the Tor instance started from Selenium) doesn't seem to read the configuration lines contained in the Tor torrc file and doesn't recognize the browser language manually set in a previous moment. So, the Tor instance is NOT my default Tor browser, it is a bare new "copy": it starts as if it was not ever configured.
So the question is: is there any way to start Tor so that it reads the torrc configuration before starting?
Alternatively: would it be possible to manually start Tor and then attach my code to THAT instance, without creating new Tor instances?
Are there any other alternatives?
Any help is appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
