-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
41 lines (33 loc) · 1.16 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 = "your_username"
PASSWORD = "your_password"
ENDPOINT = "pr.oxylabs.io:7777"
def get_chrome_proxy(user: str, password: str, endpoint: str) -> dict:
wire_options = {
"proxy": {
"http": f"http://{user}:{password}@{endpoint}",
"https": f"http://{user}:{password}@{endpoint}",
}
}
return wire_options
def execute_driver():
options = webdriver.ChromeOptions()
options.headless = True
seleniumwire_options = {
**get_chrome_proxy(USERNAME, PASSWORD, ENDPOINT),
"driver_path": ChromeDriverManager().install(),
}
driver = webdriver.Chrome(
options=options,
seleniumwire_options=seleniumwire_options,
)
try:
driver.get("https://ip.oxylabs.io/location")
return f'\nYour IP is: {driver.find_element(By.CSS_SELECTOR, "pre").text}'
finally:
driver.quit()
if __name__ == "__main__":
print(execute_driver())