-
Notifications
You must be signed in to change notification settings - Fork 3
/
proxies_randomizer.py
59 lines (52 loc) · 2.08 KB
/
proxies_randomizer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from http_request_randomizer.requests.proxy.requestProxy import RequestProxy
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from os import getcwd
from selenium.webdriver import DesiredCapabilities
from random import randrange
option = Options()
prefs = {
"translate_whitelists": {
"es": "en",
"ru": "en",
"id": "en",
"pt": "en",
"ko": "en",
"fr": "en",
"ar": "en",
"it": "en",
"nl": "en",
"th": "en",
"tr": "en",
"vi": "en",
"he": "en",
"ja": "en",
"pl": "en"
},
"translate": {"enabled": "true"},
"profile.default_content_setting_values.notifications": 2
}
option.add_experimental_option("prefs", prefs)
option.add_experimental_option('excludeSwitches', ['enable-logging'])
option.add_argument("--lang=en")
"""option.add_argument("--headless")"""
option.add_argument("--window-size=1920,1080")
req_proxy = RequestProxy()
proxies = req_proxy.get_proxy_list()
user_agents = ['Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', 'Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36']
"""profile.set_preference('devtools.jsonview.enabled', False)
profile.set_preference('intl.accept_languages', 'ru, en')
profile.set_preference("translate", "true")"""
def page_content():
PROXY = proxies[randrange(len(proxies))].get_address()
DesiredCapabilities.CHROME['proxy'] = {
"httpProxy": PROXY,
"ftpProxy": PROXY,
"sslProxy": PROXY,
"proxyType": "Manual"
}
DesiredCapabilities.CHROME["pageLoadStrategy"] = "none"
driver = webdriver.Chrome(executable_path=f"{getcwd()}\chromedriver.exe", options=option)
driver.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": user_agents[randrange(2)]})
driver.switch_to.window(driver.current_window_handle)
return driver