Selenium + Chrome headless 报ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context 可忽略并配置不输出日志
Selenium不再推荐使用PhantomJS,会报如下警告
UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '
于是从PhantomJS转移到Chrome,使用headless versions of Chrome时,首先要安装Chrome,然后下载chromedriver,再把chromedriver的地址配置到系统环境变量path中,方便调用。如果不把chromedriver的地址配置到系统环境变量的话,也可以在使用时指定chromedriver的地址。
注意Chrome和chromedriver有版本对应的要求,系统中安装了某一版本的chrome要使用对应版本的chromedriver,其实下载最新版本的Chrome和chromedriver就行了,一般都是对应的。
Chrome下载地址:https://chrome.en.softonic.com/
chromedriver下载地址:http://npm.taobao.org/mirrors/chromedriver/
不过在使用过程中,还是不如PhantomJS顺手,在windows环境下,chrome还有点问题。比如启动chromedriver的时候,会报个错。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
# webdriver.Chrome函数里有个参数executable_path,默认值是'chromedriver.exe',会搜索系统path变更,也可以修改该值,使用其他路径
# driver = webdriver.Chrome(executable_path=my_driver_path,chrome_options=chrome_options)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.baidu.com/")
[0917/002914.533:ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context.

虽然最终没有影响程序执行,但还是费了很大劲去查了一下,原因是在windows系统中Chrome无头模式下,其中的SwiftShader软件会触发断言失败,但实际上不影响程序执行,可以忽略该错误。
https://stackoverflow.com/questions/50143413/errorgpu-process-transport-factory-cc1007-lost-ui-shared-context-while-ini
但执行程序时输出这么个错总归是心里不舒服,而且还输出了其他的info信息,如果不想看到这些日志信息的话,可以设置chromedriver的日志级别,只有大于设置级别的日志还会输出,该配置参数为:log-level。如此输出干净多了。
options.add_argument('log-level=3')
# INFO = 0,
# WARNING = 1,
# LOG_ERROR = 2,
# LOG_FATAL = 3
# default is 0
最后使用完chromedriver时,最好用driver.quit()关闭。
Selenium + Chrome headless 报ERROR:gpu_process_transport_factory.cc(1007)] Lost UI shared context 可忽略并配置不输出日志的更多相关文章
- 笔记-selenium+chrome headless
笔记-selenium+chrome headless 1. selenium+chrome headless phantomjs与selenium分手了,建议使用其它无头浏览器. chro ...
- ubuntu服务器端使用无界面selenium+ chrome + headless
本来想直接用Ubuntu系统里面的firefox来实现selenium自动操作签到的,但是总是出各种问题.没办法,改为Chrome.参考:Ubuntu 线上无界面服务器 使用selenium chro ...
- chrome浏览器爬虫WebDriverException解决采用python + selenium + chrome + headless模式
WebDriverException: Message: unknown error: Chrome failed to start: crashed 第一种:如果出现下面情况: chrome浏览器有 ...
- selenium chrome headless无界面引擎
注意:PhantomJS已被舍弃 chrome headless 在打开浏览器之前添加参数 import time import sys from selenium import webdriver ...
- android webview 报 [ERROR:in_process_view_renderer.cc(189)] Failed to request GL process. Deadlock likely: 0 问题
工作中遇到 使用webview中加载含有audio标签的页面时提示[ERROR:in_process_view_renderer.cc(189)] Failed to request GL proce ...
- Ubuntu 无界面使用selenium chrome + headless
1. 安装 selenium : sudo pip install selenium 2. 安装 chromdriver: 进入 淘宝镜像源 下载 chromdriver, 可以查看 notes.tx ...
- selenium +chrome headless Adhoc模式渲染网页
mannual和adhoc模式比较 Manual vs. Adhoc In the script above, we start the ChromeDriver server process whe ...
- selenium +chrome headless Manual 模式渲染网页
可以看看这个里面的介绍,写得很好.https://duo.com/blog/driving-headless-chrome-with-python from selenium import webdr ...
- ubuntu中如何安装selenium+chrome(headless)无界面浏览器?
selenium是一个Web的自动化测试工具,它可以根据我们的指令,让浏览器自动加载页面,获取需要的数据,甚至页面截屏,或者判断网站上某些动作是否发生.但是它自身不带浏览器,不支持浏览器的功能,因此它 ...
随机推荐
- Front-end: Using blurred backgrounds with contents unaffected.
Purpose: Using a picture as the background of a page with blurred effect, while the content not blur ...
- 印象笔记无法连服务器(internet explore的问题)
https://www.zhihu.com/question/20214497?sort=created
- Python全栈之路----流程控制+循环
(一)流程控制 1.单分支结构 if 条件: 满足条件后要执行的代码 2.双分支结构: if 条件: 满足条件后要执行的代码 else : if 不满足就执行这个代码 3.多分支结构:if ...
- python------SocketServer (0809)
socket(一对一) 与socketserver 一.socketserver 1. 正式定义:The socketserver module simplifies the task of writ ...
- 使用 jest 测试 react component 的配置,踩坑。
首先安装依赖 npm i jest -g npm i jest babel-jest identity-obj-proxy enzyme enzyme-adapter-react-15.4 react ...
- 查询正在运行的请求及其后台对应SQL
SELECT a.event , s.actual_start_date , a.sid, a.serial#, sa.sql_fulltext , sa.sql_text , v.user_conc ...
- PythonStudy——名称空间 Name space
# 名称空间:就是名字与地址的对应关系,可以被Python解释器遍历查找,采用堆栈存储方式 # 三种名称空间# Built-in:内置名称空间:系统级,一个:随解释器执行而产生,解释器停止而销毁# G ...
- shell脚本使用## or %%
今天写脚本的时候,遇到一个文件路径需要去掉右边一部分,当时就想到了这个,但是很久没用过了,很多不记得了,记录一下这种用法 1:vim test.sh #!/bin/bash location=/f ...
- Vue 移动端常用tap事件封装
基于Vue的移动端项目,有些时间原生并没用提供,需要我们自己手动封装,可以封装一些自定义指令来供全局使用. 本文封装了 tap, swipe, swipeleft, swiperight, swipe ...
- mysql查询中AND与OR注意事项
在查询的where条件中,and要优于or 如果要改变优先级, 需要在最小逻辑判断的条件外加括号(),例如: select * from `table_name` where (`type` = 1 ...