-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
36 lines (25 loc) · 948 Bytes
/
config.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
from selenium.webdriver.chrome.options import Options
import logging
from fake_useragent import UserAgent
import undetected_chromedriver as webdriver
import random
def setup_logging():
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
def get_webdriver(headless=True):
chrome_options = Options()
ua = UserAgent()
user_agent = ua.random
if headless:
chrome_options.add_argument("--headless")
chrome_options.add_argument(f"--user-agent={user_agent}")
chrome_options.add_argument("--use_subprocess")
driver = webdriver.Chrome(options=chrome_options)
min_width, max_width = 900, 1401
min_height, max_height = 700, 801
random_width = random.randint(min_width, max_width)
random_height = random.randint(min_height, max_height)
driver.set_window_size(random_width, random_height)
driver.implicitly_wait(2)
return driver