Last active
November 19, 2021 16:09
-
-
Save ashhadulislam/27398278c08d5761492122bdf903ede5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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