from selenium.webdriver.common.by import By
from seleniumwire import webdriver
# A package to have a chromedriver always up-to-date.
from webdriver_manager.chrome import ChromeDriverManager
USERNAME = "user-USERNAME"
PASSWORD = "PASSWORD"
ENDPOINT = "t.pr.thordata.net:12233"
def chrome_proxy(user: str, password: str, endpoint: str) -> dict:
wire_options = {
"proxy": {
"http": f"http://{user}:{password}@{endpoint}",
"https": f"https://{user}:{password}@{endpoint}",
}
}
return wire_options
def execute_driver():
options = webdriver.ChromeOptions()
options.add_argument('--headless')
proxies = chrome_proxy(USERNAME, PASSWORD, ENDPOINT)
driver = webdriver.Chrome(
ChromeDriverManager(driver_version='<VERSION>').install(), options=options, seleniumwire_options=proxies
)
try:
driver.get("https://ipinfo.thordata.com/")
return f'\nYour IP is: {driver.find_element(By.CSS_SELECTOR, "pre").text}'
finally:
driver.quit()
if __name__ == '__main__':
print(execute_driver())