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

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

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀