为了账号安全,请及时绑定邮箱和手机立即绑定

硒和谷歌浏览器驱动程序不会在linux python上运行

硒和谷歌浏览器驱动程序不会在linux python上运行

波斯汪 2022-09-13 17:20:16
当我把我的代码放在理论上看起来应该工作时,我无法让铬运行,我甚至遵循了教程,但我不断得到同样的错误消息。这是我放的代码:from selenium import webdriver#chromedriver varible with exact location to where its savedchromedriver = "/home/jackmiller/Downloads/chromedriver"#varible of drive to run open up the chrome driver which is located#on my machine as chromedriver varible chromedriverdriver = webdriver.Chrome(chromedriver)#open this websitedriver.get('https://youtube.com')当我在终端中运行代码时,这是它返回的内容:Traceback (most recent call last):  File "automation.py", line 8, in <module>    driver = webdriver.Chrome(chromedriver)  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__    desired_capabilities=desired_capabilities)  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__    self.start_session(capabilities, browser_profile)  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session    response = self.execute(Command.NEW_SESSION, parameters)  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute    self.error_handler.check_response(response)  File "/usr/local/lib/python2.7/dist-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.)它根本没有打开铬
查看完整描述

2 回答

?
慕妹3242003

TA贡献1824条经验 获得超6个赞

您是否尝试过使铬驱动程序可执行?sudo chmod a+x chromedriver



查看完整回答
反对 回复 2022-09-13
?
牧羊人nacy

TA贡献1862条经验 获得超7个赞

你试过吗: options.add_argument(“--远程调试端口=9222”)

从此错误报告:https://github.com/SeleniumHQ/selenium/issues/6049

解决方法是指定远程调试端口作为ChromeOptions的参数,例如:options.add_argument(“-远程调试端口= 9222”),如果您在容器中运行,请将驱动程序设置为无外设,如sops.headless = True,否则使用类似pyvirtualdisplay之类的东西作为屏幕截图。


查看完整回答
反对 回复 2022-09-13
  • 2 回答
  • 0 关注
  • 122 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信