吓坏的心
2021-05-21 11:02
采纳率: 100%
浏览 123
已采纳

linux python DevToolsActivePort file doesn't exist

使用宝塔面板安装了python项目管理器

chrome 安装的时候安装在了 /opt/google/chrome/ 这个目录下 将chrome做了软连接到/usr/local/bin/下

chromedriver 在/usr/local/bin/ 下

使用selenium爬取数据总是提示

Traceback (most recent call last):
  File "/www/wwwroot/python/index.py", line 38, in <module>
    browser = webdriver.Chrome(options=chrome_options)
  File "/www/wwwroot/python/damai_venv/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/www/wwwroot/python/damai_venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/www/wwwroot/python/damai_venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/www/wwwroot/python/damai_venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/www/wwwroot/python/damai_venv/lib/python3.7/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/local/bin/chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

求大佬指导一下

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • CSDN专家-黄老师 2021-05-21 12:22
    已采纳

    你的代码是不是有打开谷歌浏览器?如果你的系统是命令行,没有gui界面,不能打开浏览器,要设置

    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument("window-size=1024,768")
    chrome_options.add_argument("--no-sandbox")
    driver = webdriver.Chrome(chrome_options=chrome_options)

    已采纳该答案
    评论
    解决 1 无用
    打赏 举报
  • 有问必答小助手 2021-05-21 14:11

    您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

    如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

    ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题