python-3.x - Selenium.webdriver:Chrome 无法启动:崩溃。作为 Cronjob 运行时
问题描述
我正在尝试让我的 selenium 脚本作为 Cron 运行。该脚本在终端上运行没有问题,并为我提供了所需的输出。但是作为 Cron 运行我得到了错误:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed.
(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.)
这是我的驱动程序初始化。我在代码中添加了应该解决问题的所有内容,但它对我不起作用:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-extensions')
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-plugins-discovery")
chrome_options.add_argument("--start-maximized")
chrome_options.binary_location = "/usr/bin/google-chrome"
chrome_options.headless = True
caps = DesiredCapabilities().CHROME
caps["marionette"] = True
os.environ["webdriver.chrome.driver"] = '/usr/bin/chromedriver'
driver = webdriver.Chrome(executable_path='/usr/bin/chromedriver',options=chrome_options) # <-here it crashes
driver.delete_all_cookies()
driver.set_window_size(1920, 1080)
driver.set_window_position(0, 0)
chromedriver --version 和 whereis chromedriver:
ChromeDriver 86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378})
chromedriver: /usr/bin/chromedriver /usr/local/bin/chromedriver
google-chrome --version 和 whereis google-chrome:
Google Chrome 86.0.4240.183
google-chrome: /usr/bin/google-chrome
就像我之前说的那样,它在终端上运行,但是通过这个 cronjob,我得到了上面的错误:
*/5 * * * * user ~/HTGMQ/run.sh
运行.sh
#!/bin/bash
cd ~/HTGMQ/ # i know its redundant but who cares
/usr/bin/python3 ~/HTGMQ/script.py
我真的不知道我该怎么办了:(
谢谢回复和回答
解决方案
推荐阅读
- sql - 如何从返回的子查询中选择没有值的记录(具有逗号分隔值)?
- javascript - 让分页更好一点 Vuejs
- arduino - 为arduino重写SdFat中的行
- concurrency - 线性化和静态一致性有什么区别?
- configuration - 如何更改 zpool 的默认 zfs 选项?
- javascript - TypeScript:使用动态导入的工厂模式不允许构造对象的新实例以进行组合
- vue.js - 在 vuejs 中使用 axios 方法处理错误
- arrays - 反应我如何多映射值以提高效率
- google-cloud-platform - Terraform - 创建 Google Cloud SQL 实例不起作用
- python - Python 3.7.0 - 结构 calcsize、错误或功能?