目标:启动时自动执行python selenium脚本。 我当前的解决方案已经工作了半年,但是3天前更新了我的pi之后,python崩溃并出现以下异常: selenium.common.exceptions.WebDriverException:消息:未知错误:DevToolsActivePort文件不存在
这是我的初始化代码:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(chrome_options=chrome_options, service_args=["--verbose", "--log-path=/home/pi/chromedriver.log"])
browser.implicitly_wait(10)
browser.set_window_size(800, 600)
browser.get(...)
然后chromedriver返回:
[1571045268,786][INFO]: Launching chrome: /usr/bin/chromium-browser --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disable-web-resources --enable-automation --enable-logging --force-fieldtrials=SiteIsolationExtensions/Control --headless --ignore-certificate-errors --load-extension=/tmp/.org.chromium.Chromium.ka9jxU/internal --log-level=0 --metrics-recording-only --no-first-run --no-sandbox --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.org.chromium.Chromium.13RyA2 data:,
: getrandom indicates that the entropy pool has not been initialized. Rather than continue with poor entropy, this process will block until entropy is available.
[1571045328,829][INFO]: Failed to connect to Chrome. Attempting to kill it.
[1571045328,842][INFO]: [4c8ff7afd4ca8a1d7e7d0313509df6dc] RESPONSE InitSession ERROR unknown error: DevToolsActivePort file doesn't exist
[1571045328,842][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1571045328,842][DEBUG]: Log type 'browser' lost 0 entries on destruction
[0100/000000.682302:ERROR:zygote_linux.cc(660)] write: Datenübergabe unterbrochen (broken pipe) (32)
我正在使用自动启动文件〜/ .config / lxsession / LXDE-pi / autostart 和以下命令:@/home/pi/script/main.py > /home/pi/script.log 2>&1 &
(通过将main.py标记为可执行文件和使用python3。
如果我通过ssh手动启动脚本,我没有任何问题。因此,我认为这是由于缺少环境变量或在启动/自动启动过程中导致铬崩溃而引起的。如您所见,我已经尝试过this stack overflow question的答案。
我当前的铬版本为Chromium 72.0.3626.121 Built on Raspbian , running on Raspbian 9.11
,
chromedriver版本为ChromeDriver 72.0.3626.121
答案 0 :(得分:0)
我自己找到了答案,它是由getrandom indicates that the entropy pool has not been initialized. Rather than continue with poor entropy, this process will block until entropy is available.
引起的,它表明缺少熵源,导致chromedriver崩溃,因为建立熵源需要很长时间。我要做的就是安装 rng-tools ,脚本没有崩溃。有关更多详细信息,请阅读此blog post,它有助于我解决此问题。