Skip to content

Instantly share code, notes, and snippets.

@ashhadulislam
Created November 19, 2021 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashhadulislam/bcd8cadfc5bd7b23c44396db83b4a539 to your computer and use it in GitHub Desktop.
Save ashhadulislam/bcd8cadfc5bd7b23c44396db83b4a539 to your computer and use it in GitHub Desktop.
# import from selenium
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = '/Applications/Tor Browser.app/Contents/MacOS/firefox'
# the location of firefox package inside Tor
if os.path.exists(binary) is False:
raise ValueError("The binary path to Tor firefox does not exist.")
firefox_binary = FirefoxBinary(binary)
def get_browser(binary=None,options=None):
global browser
# only one instance of a browser opens, remove global for multiple instances
if not browser:
browser = webdriver.Firefox(firefox_binary=binary,options=options)
return browser
browser = None
browser = get_browser(binary=firefox_binary)
# click on connect to connect the tor browser to the remote nodes
browser.find_element_by_xpath('//*[@id="connectButton"]').click()
time.sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment