-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexamples.py
More file actions
64 lines (53 loc) · 2 KB
/
Copy pathexamples.py
File metadata and controls
64 lines (53 loc) · 2 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import time
import random
from selenium import webdriver
from fake_useragent import UserAgent
from datetime import datetime as dt
# https://pypi.org/project/fake-useragent/
# # read the docs : https://selenium-python.readthedocs.io/
# need add function for change Proxy and UserAgent !!!
def add_random_ua():
fake_ua = UserAgent().random
for item in options.arguments:
if '--user-agent=' in item:
options.arguments.remove(item)
options.add_argument(f'--user-agent={fake_ua}')
print(f'User-agent: {fake_ua}')
def add_random_proxy():
random_proxy = PROXY_LIST[random.randint(0, len(PROXY_LIST) - 1)] # PROXY_LIST taking from .txt file
for item in options.arguments:
if '--proxy-server=' in item:
options.arguments.remove(item)
options.add_argument(f'--proxy-server={random_proxy}')
print(f'Proxy-server: {random_proxy}')
chromedriver = 'C:\\Users\\User\\Desktop\\chromedriver\\chromedriver.exe'
options = webdriver.ChromeOptions()
options.add_argument("--window-size=1024,768")
options.add_argument("--disable-notifications")
options.add_argument("--disable-popup-blocking")
options.add_argument("--user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument("--profile-directory=Default")
options.add_argument("--ignore-certificate-errors")
while True: #
# print(f'Timestamp: {dt.now().strftime("%Y-%m-%d %H:%M:%S")}')
add_random_ua()
add_random_proxy()
web = webdriver.Chrome(chromedriver, options=options)
web.implicitly_wait(30)
web.get(URL)
# testing code here ...
web.quit()
# change to new window by Link
# ...
LINK = 'https://...'
# ...
#driver.implicitly_wait(3)
driver.maximize_window()
driver.get('LINK')
driver.find_element_by_xpath("xpath").click()
driver.find_element_by_xpath("xpath").click()
time.sleep(2)
# driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
driver.switch_to.window(window_name)
time.sleep(2)
t_driver = driver.current_url