直接用headless ChromeDriver。可直接在Google主页下载个ChromeDriver,都是支持headless的
禁止图片加载,提高效率
from selenium import webdriver
def createBrowser(testmode):
if testmode == 'test':
browser = webdriver.Chrome()
browser.maximize_window()
else:
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.maximize_window()
return browser
网友评论