-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathexample.py
More file actions
39 lines (33 loc) · 1.55 KB
/
Copy pathexample.py
File metadata and controls
39 lines (33 loc) · 1.55 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
36
37
38
39
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
from webdriver_manager.firefox import GeckoDriverManager
import time
HOSTNAME = 'us.decodo.com' #Proxy host:port configuration
PORT = '10000'
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))
return options
def webdriver_example(): #Installs the latest selected webdriver and uses proxy to reach target
if DRIVER == 'FIREFOX':
browser = webdriver.Firefox(service=Service(GeckoDriverManager().install()),
options=smartproxy())
elif DRIVER == 'CHROME':
browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()),
options=smartproxy())
browser.get('http://ip.decodo.com/ip') #Target URL
print(browser.page_source) #Prints out desired element of target URL
browser.quit()
if __name__ == '__main__':
webdriver_example()