我一直在 Raspberry Pi 5 上运行
Selenium
、Chromedriver
和 Python。因为 Chromedriver
确实没有 ARM 版本可供下载,但 APT 上有一个版本
https://forums.raspberrypi.com/viewtopic.php?p=2155925#p2155925
所以,我一直在使用这个,当我通过 Geany 运行时,一切都运行良好
所以,我已经完成了,现在想通过 CRON 运行这个 python 脚本,所以我输入了详细信息,但出现了错误。
Traceback (most recent call last): File "/home/dean/main_venv/luxpowerdl.py", line 69, in <module>
driver = webdriver.Chrome(service=service)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/dean/main_venv/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
super().__init__( File "/home/dean/main_venv/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 61, in __init__
super().__init__(command_executor=executor, options=options) File "/home/dean/main_venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 208, in __init__
self.start_session(capabilities) File "/home/dean/main_venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 292, in start_session
response = self.execute(Command.NEW_SESSION, caps)["value"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/dean/main_venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
self.error_handler.check_response(response) File "/home/dean/main_venv/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally. (session not created: 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.) Stacktrace:
#0 0x5555f50dc3e4 <unknown>
#1 0x5555f4e11ac8 <unknown>
#2 0x5555f4e40fac <unknown>
#3 0x5555f4e3dc44 <unknown>
#4 0x5555f4e7cf08 <unknown>
#5 0x5555f4e48d74 <unknown>
#6 0x5555f4e49760 <unknown>
#7 0x5555f50a6a74 <unknown>
#8 0x5555f50a9e04 <unknown>
#9 0x5555f5096d7c <unknown>
#10 0x5555f50aa714 <unknown>
#11 0x5555f507f0e0 <unknown>
#12 0x5555f50cbbc4 <unknown>
#13 0x5555f50cbdc0 <unknown>
#14 0x5555f50db5b4 <unknown>
#15 0x7fff46fcee58 <unknown>
#16 0x7fff47037f9c <unknown>
APT安装的本地
Chromedriver
是usr/bin,拥有Root权限,权限也不错。
usr/bin 在我的 $PATH 中。
因此,Python 文件在我的用户终端 Geany 上运行良好,我的用户名位于 Root 组中,Chromedriver 以 root 为所有者,root 的权限为 rwx,组为 r-x,其他为 r-x,并且也被标记为可执行文件.
有什么想法我可以让
cron
(使用crontab -e
)访问chromedriver
。
PS,Chromium浏览器已安装。全部使用运行 Debian Bookworm 的 Raspberry Pi 5。
终于在我的 CRON 条目中找到了必须使用 DISPLAY=:0 的参考,我认为这也行不通,因为它需要 X 才能运行,但 Debian Bookworm 正在使用 Wayland,无论如何我试了一下,它运行得很好。 所以我的 Cron 条目现在是
*/15 * * * * DISPLAY=:0 /home/dean/main_venv/bin/python main_venv/luxpowerdl.py > main/venv/logs/luxpowerdl.log 2>&1