forked from AiRanthem/xmu-daily-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webdriver.py
39 lines (29 loc) · 967 Bytes
/
webdriver.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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.webdriver import WebDriver
from utils import debug
chrome_options = Options()
# 谷歌文档提到需要加上这个属性来规避bug
chrome_options.add_argument('--disable-gpu')
# 隐藏滚动条, 应对一些特殊页面
chrome_options.add_argument('--hide-scrollbars')
# 不加载图片, 提升速度
chrome_options.add_argument('blink-settings=imagesEnabled=false')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--disable-dev-shm-usage")
# chrome_options.add_argument('--headless')
driver = None
def refresh():
close()
global driver
if debug:
driver = webdriver.Edge()
else:
driver = webdriver.Chrome(options=chrome_options)
driver.maximize_window()
def get() -> WebDriver:
global driver
return driver
def close():
if driver is not None:
driver.close()