-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestproxy.py
More file actions
35 lines (29 loc) · 1.36 KB
/
Copy pathtestproxy.py
File metadata and controls
35 lines (29 loc) · 1.36 KB
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
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options as ChromeOptions
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from webdriver_manager.chrome import ChromeDriverManager
import time
HOSTNAME = 'az.smartproxy.com' #Proxy host:port configuration
PORT = '30001'
DRIVER = 'CHROME' #Select 'CHROME' or 'FIREFOX'
def smartproxy(): #Selects appropriate driver and sets up proxy
if DRIVER == 'FIREFOX':
options = FirefoxOptions()
elif DRIVER == 'CHROME':
options = ChromeOptions()
else:
raise ValueError("Invalid driver specified")
proxy_str = '{hostname}:{port}'.format(hostname=HOSTNAME, port=PORT)
options.add_argument('--proxy-server={}'.format(proxy_str))
options.add_argument("--disable-webrtc")
options.add_argument("--disable-gpu")
return options
def webdriver_example(): #Installs the latest selected webdriver and uses proxy to reach target
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()),
options=smartproxy())
browser.get('https://ip.smartproxy.com/json') #Target URL
print(browser) #Prints out desired element of target URL
if __name__ == '__main__':
webdriver_example()