selenium 无头为什么错误
有头模式没有错误程序代码:
from webdriver_manager.chrome import ChromeDriverManager import time from requestium import Session, Keys ua ='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36' s = Session(webdriver_path=ChromeDriverManager().install(), default_timeout=15, browser='chrome') ra = s.get('https://bbs.bccn.net/forum-246-1.html') s.transfer_session_cookies_to_driver() s.driver.get('https://bbs.bccn.net/forum-246-1.html') time.sleep(100)
启动无头模式却发生错误
程序代码:
from webdriver_manager.chrome import ChromeDriverManager from selenium import webdriver from selenium.webdriver.support.ui import Select from selenium.webdriver.support import expected_conditions as EC import time from requestium import Session, Keys ua ='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36' chrome_options = webdriver.ChromeOptions() chrome_options.add_argument("user-agent={}".format(ua)) chrome_options.add_argument('--headless') # 啟動無頭模式 chrome_options.add_argument('--disable-gpu') # windowsd必須加入 s = Session(webdriver_path=ChromeDriverManager().install(), default_timeout=15, browser='chrome',chrome_options=chrome_options) ra = s.get('https://bbs.bccn.net/forum-246-1.html') s.transfer_session_cookies_to_driver() s.driver.get('https://bbs.bccn.net/forum-246-1.html') time.sleep(100)