During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/project/login_by_user.py", line 175, in open_client
driver = webdriver.Chrome(const.driver_path_80, chrome_options=chrome_options)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
1. 原因1:
chromedriver的版本与google-chrome版本不一致
查看方式:chromedriver --version 和 google-chrome --version 要是版本不一致引起的问题,可以重新安装成匹配的版本。
安装示例:
(1)先安装 google-chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum install -y google-chrome-stable_current_x86_64.rpm
#查看版本号
google-chrome --version
(2)再安装chromedriver:一定要先查看google-chrome版本号,安装匹配的版本(最好是版本号一模一样),chromedriver版本查找页面:
http://chromedriver.storage.googleapis.com/index.html
,找到合适的版本号
#通过上面链接,找到合适的版本下载
wget http://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
#移动到启动路径
mv chromedriver /usr/local/bin/
#分配权限
chmod 777 /usr/local/bin/chromedriver
#查看版本号
chromedriver --version
(3)安装selenium,由于Selenium是标准的python包,这里直接基于pip进行安装。
pip install selenium
2. 原因2: Chrome启动参数未添加完整,我就是因为第二行--headless被注释掉而报错,排查了好久,所以以下几行配置参数必不可少。 完整的参数如下:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
至此,就完成了chrome的驱动安装了。
参考链接:
CentOS上安装Selenium和google Driver的过程以及问题记录
chromedriver版本号对应链接
Centos之Chrome浏览器安装-yellowcong
使用
Selenium
模拟谷歌
Chrome浏览器
时
报错
怎么办
对于动态网页的内容爬取,使用
selenium
模拟谷歌
chrome浏览器
进行网页操作和内容爬取是很好的一个选择。但在初次使用时,可能会出现
报错
找不到
谷歌浏览器
。
源代码如下:
from
selenium
im
port
webdriver
browser=webdriver.
Chrome
(executable_path=‘D:/anaconda3/
chrome
driver.exe’)
报错
信息如下截图所示:
出现这种错误时,一般是由于谷歌
chrome
在这个例子中,我们使用WebDriverWait类等待目标元素加载完成,并使用ActionChains类模拟鼠标移动和点击操作。可以使用location_once_scrolled_into_view属性将元素滚动到视野范围内,或者使用ActionChains类模拟鼠标操作。可以使用execute_script()方法将元素滚动到视野范围内,或者使用ActionChains类模拟鼠标操作。可以使用WebDriverWait类等待元素变为可交互状态,或者通过JavaScript来修改元素状态。
selenium
同时打开多个
chrome
driver对象时候
unknown
error
:
DevTools
Active
Port
file
doesn't
exist
第一步:检查浏览器版本与驱动器的版本是否一致。
使用
selenium
启动
谷歌
Chrome浏览器
的时候,是需要用到
chrome
dirver驱动器的,而且两者之间的版本是需要匹配的。
下面提供是的
谷歌浏览器
版本,对应的...
Traceback (most recent call last):
File
"C:/Users/yuhao/PycharmProjects/untitled/
selenium
/
selenium
_first.py", line 13, in <module>
driver.get('www.baidu.com')
Fi...
1. 背景
在使用
selenium
浏览器渲染技术,爬取网站信息时,默认情况下就是一个普通的纯净的
chrome浏览器
,而我们平时在使用浏览器时,经常就添加一些插件,扩展,代理之类的应用。相对应的,当我们用
chrome浏览器
爬取网站时,可能需要对这个
chrome
做一些特殊的配置,以满足爬虫的行为。
常用的行为有:
禁止图片和视频的加载:提升网页加载速度。
添加代理:用于翻墙访问某些页面,或者应对IP访问频率限制的反爬技术。
使用移动头:访问移动端的站点,一般这种站点的反爬技术比较薄弱。
添加扩展:像正常使用浏览
使用
selenium
打开浏览器
报错
报错
信息
selenium
. common.exceptions . WebDriverException: Message:
chrome
driver’ executable needs to be in PATH
解决
方法
1. 检查
Chrome
driver驱动和
谷歌浏览器
版本是否一致
打开cmd输入
chrome
driver可以查看驱动版本
在
谷歌浏览器
中打开设置–关于
Chrome
,可以查看
谷歌浏览器
版本。
谷歌浏览器
和
chrome
driver驱动版本要一致,若
今天
调用
selenium
库驱动
chrome浏览器
时遇到了这个
报错
DevTools
listening on ws://127.0.0.1:7100/
devtools
/browser/8500db96-f724-401a-a52a-d7aebcef5a6b
[79052:78172:1123/043504.039:
ERROR
:
chrome
_browser_main_extra_parts_metrics.cc(226)] crbug.com/1216328: Checking Bluetooth avai