python - headless chromedriver python "uncaught tagerror"

标签 python selenium selenium-chromedriver

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')

在 Windows 7、Python 3.6.4、Selenium 3.9.0、Chromedriver 2.43 上运行代码代码在非 headless 模式下执行没有问题。在 headless 模式下,在Anaconda Prompt中执行,连续输出以下错误:

Error

最佳答案

由于您在 Windows 上运行,因此在使用 headless 时需要添加 --disable-gpu 参数。请参阅https://developers.google.com/web/updates/2017/04/headless-chrome

在您所说的使用的 selenium 版本 3.9 中,您还可以使用便捷方法 set_headless() ,它将添加 --headless--disable-gpu 为您服务。在较新的版本中,它是一个 setter options.headless = True

关于python - headless chromedriver python "uncaught tagerror",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53220117/

相关文章:

python - 如何在 seaborn 中显示所有数字图例值?

python - 如何从 Docker 容器启动指定的 conda 环境?

javascript - Selenium 中的 XPath 是否针对 DOM 或 HTML 文件运行?

python - 通过 python selenium 在 Chrome 中限制 CPU

python - 如果我在上一次运行退出后立即重新启动,则 socket.accept() 中的无效参数异常

python - SQLAlchemy + cx_oracle 和特殊字符

java - 在 selenium 的 PageFactory 上选择对象

Python Selenium ConnectionResetError : [WinError 10054] An existing connection was forcibly closed by the remote host

python - 尝试通过 Selenium 和 Python 使用 ChromeDriver Chrome 进行抓取时,地址栏显示数据 :,

python - seleniumexecute_script() 返回错误值