Crontab Selenium Chromium in Raspberry pi (未知错误: DevToolsActivePort 文件不存在)



我正在用硒和铬运行crontab。

如果我不使用 crontab 运行脚本,则一切正常。

我想在启动时显示屏幕,但它给了我这个错误。

(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so 
ChromeDriver is assuming that Chrome has crashed.)

这是我的cron:

@reboot DISPLAY=:0 sudo /usr/bin/python3 /home/pi/main.py > /home/pi/selenium.log 2>&1

我的蟒蛇代码:

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome( executable_path="/usr/bin/chromedriver" ,
service_args= [ "--verbose", "--log-path=/tmp/CHROMIUM_LOG" ],
options = chrome_options
)

我已经从这篇文章中尝试过了。

此外,如果有任何其他方法可以在stratup上运行脚本并显示浏览器,请告诉我。

我对此进行了大量实验,它对我有用的唯一方法是设置 2 分钟计时器来启动脚本。

我将 crontab 更改为:

@reboot DISPLAY=:0 sleep 120 && sudo /usr/bin/python3 /home/pi/main.py > /home/pi/selenium.log 2>&1

最新更新