Skip to content

Instantly share code, notes, and snippets.

@ashhadulislam
Last active November 19, 2021 16:09
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/27398278c08d5761492122bdf903ede5 to your computer and use it in GitHub Desktop.
Save ashhadulislam/27398278c08d5761492122bdf903ede5 to your computer and use it in GitHub Desktop.
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.firefox.options import Options
# path to the firefox binary inside the Tor package
binary = '/Applications/Tor Browser.app/Contents/MacOS/firefox'
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
# following makes the browser invisible
options = Options()
options.headless = True
browser = None
browser = get_browser(binary=firefox_binary,options=options)
browser.find_element_by_xpath('//*[@id="connectButton"]').click()
time.sleep(3)
url='https://check.torproject.org/'
browser.get(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment