Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x Selenium.webdriver:Chrome启动失败:崩溃。当作为Cronjob运行时_Python 3.x_Selenium_Selenium Webdriver_Cron_Selenium Chromedriver - Fatal编程技术网

Python 3.x Selenium.webdriver:Chrome启动失败:崩溃。当作为Cronjob运行时

Python 3.x Selenium.webdriver:Chrome启动失败:崩溃。当作为Cronjob运行时,python-3.x,selenium,selenium-webdriver,cron,selenium-chromedriver,Python 3.x,Selenium,Selenium Webdriver,Cron,Selenium Chromedriver,我正试图让我的selenium脚本作为Cron运行。 脚本在终端上运行没有问题,并提供了所需的输出。 但作为Cron运行时,我得到了一个错误: selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed. (unknown error: DevToolsActivePort file doesn't exist) (The process st

我正试图让我的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)
谷歌chrome——谷歌chrome的版本和位置:

Google Chrome 86.0.4240.183
google-chrome: /usr/bin/google-chrome
正如我之前所说,manuel在终端上工作,但通过这个cronjob,我得到了上面的错误:

*/5 * * * * user ~/HTGMQ/run.sh
run.sh

#!/bin/bash
cd ~/HTGMQ/ # i know its redundant but who cares
/usr/bin/python3 ~/HTGMQ/script.py

我真的不知道我该怎么做了:(


Thx用于回复和回答

不带“-profile directory=Default”的情况下尝试使用“-profile directory=Default”。(如果有人当前正在使用该配置文件,则此操作将不起作用…)不幸的是,我仍然收到相同的错误尝试在Cron作业的顶部添加
DISPLAY:=0。我遇到了相同的问题,并为我解决了它。
#!/bin/bash
cd ~/HTGMQ/ # i know its redundant but who cares
/usr/bin/python3 ~/HTGMQ/script.py