解决selenium报错--unknown error: DevToolsActivePort file doesn‘t exist
发布日期:2022-03-18 18:19:15
浏览次数:2
分类:技术文章
本文共 2005 字,大约阅读时间需要 6 分钟。
早上在linux下用selenium启动Chrome时出现问题:
报错:Traceback (most recent call last): File "get2.py", line 62, inbrowser = webdriver.Chrome() File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__ desired_capabilities=desired_capabilities) File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__ self.start_session(desired_capabilities, browser_profile) File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute self.error_handler.check_response(response) File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, 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.) (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.9.0-6-amd64 x86_64)
解决方案:
加上代码:from selenium.webdriver.chrome.options import Optionschrome_options = Options()chrome_options.add_argument('--no-sandbox')chrome_options.add_argument('--disable-dev-shm-usage')chrome_options.add_argument('--headless')browser = webdriver.Chrome(chrome_options=chrome_options)
其中
“–no-sandbox”参数是让Chrome在root权限下跑 “–headless”参数是不用打开图形界面 可以额外加这些参数获得更好体验chrome_options.add_argument('blink-settings=imagesEnabled=false')chrome_options.add_argument('--disable-gpu')
转载地址:https://zhang0peter.blog.csdn.net/article/details/83502641 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年03月27日 10时01分33秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
maven中的setting.xml 配置文件
2019-04-26
MySQL的Limit详解
2019-04-26
java \t,\n,\r,\b,\f 的作用
2019-04-26
java8 LocalDate 根据时间获取星期几
2019-04-26
Base64 加密解密
2019-04-26
Excel表格身份证号显示不完整问题
2019-04-26
今日份实操——(HTML+CSS)浮动布局练习
2019-04-26
今日份学习——(HTML+CSS)其他表单的属性
2019-04-26
HTML——背景、渐变
2019-04-26
HTML——多媒体技术
2019-04-26
HTML——3D动画 热点图
2019-04-26
HTML——steps 奔跑的白熊
2019-04-26
HTML——3D移动、3D透视、3D效果、3D呈现案例效果
2019-04-26
HTML——CSS3新属性
2019-04-26
HTML——布局技巧
2019-04-26
HTML——过渡transition 进度条
2019-04-26
HTML——3D旋转+动画 旋转木马案例
2019-04-26
HTML——响应式布局
2019-04-26
HTML——携程旅游案例
2019-04-26