吓坏的心 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条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备