-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.py
50 lines (38 loc) · 1.38 KB
/
helpers.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
import os
import time
from selenium import webdriver
def get_web_driver(file_dir=None, headless=True):
if file_dir is None:
file_dir = os.path.realpath(__file__)
if not os.path.exists(file_dir):
os.makedirs(file_dir)
chop = webdriver.ChromeOptions()
prefs = {
'download.default_directory': file_dir,
'profile.default_content_settings.popups': 0
}
if headless:
#chop.add_argument('--headless')
chop.add_argument('--disable-gpu')
chop.add_argument('--window-size=1280x1696')
chop.add_argument('--ignore-certificate-errors')
chop.add_experimental_option("prefs", prefs)
file_path = os.path.dirname(os.path.realpath(__file__))
chromedriver = os.path.join(file_path, 'chromedriver')
driver = webdriver.Chrome(chromedriver, options=chop)
driver.set_window_size(1920, 1080)
return driver
def wait_function(func, timeout_param=None):
def inner_func(*args, **kwargs):
timeout = 10 if timeout_param is None else timeout_param
start_time = time.time()
while True:
try:
return func(*args, **kwargs)
except Exception as ex:
duration = time.time() - start_time
print(duration)
if duration > timeout:
raise ex
time.sleep(0.5)
return inner_func