简体   繁体   中英

headless chromedriver python "uncaught tagerror"

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument("--headless")

chrome_options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"')
chrome_options.add_argument("--window-size=1920x1080")
chrome_options.add_argument("--disable-extensions")
driver = webdriver.Chrome(chrome_options=chrome_options)

driver.get('https://www.mycarinfo.com.my/Valuation/SearchVehicle?version=free')

Running the code on Windows 7, Python 3.6.4, Selenium 3.9.0, Chromedriver 2.43 The code executes without issue in non-headless mode. In headless mode, executed in Anaconda Prompt, outputs the following error continuously:

错误

Since you're running on windows, you'll need to add the --disable-gpu argument when using headless. See https://developers.google.com/web/updates/2017/04/headless-chrome

In selenium version 3.9 which you say you're using, you can also use the convenience method set_headless() which will add both --headless and --disable-gpu for you. In newer versions it's a setter options.headless = True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM