在chromedriver异常升级到Debian Buster之后,Python splinter脚本失败

时间:2019-09-05 18:17:29

标签: python-3.x selenium selenium-chromedriver raspbian splinter

我最近将我的树莓3从Stretch升级到了Debian Buster。我有几个使用splinter,selenium和chromedriver的python脚本。升级后,脚本失败。在尝试进行故障排除时,我创建了一个简单的脚本,该脚本可以按预期工作:

    from selenium import webdriver
    from splinter import Browser

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--headless")
    driver = webdriver.Chrome(options=chrome_options)
    driver.get('https://python.org')
    html = driver.page_source
    print(html)
    driver.quit()

稍微修改脚本以使用splinter:

    from selenium import webdriver
    from splinter import Browser

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--headless")
    with Browser('chrome', headless=True, options=chrome_options) as browser:
        browser.visit('https://python.org')
        print(browser.html)

给予:

Traceback (most recent call last):
  File "sel.py", line 8, in <module>
    print(browser.html)
  File "/usr/local/lib/python3.7/dist-packages/splinter/driver/webdriver/__init__.py", line 201, in html
    return self.driver.page_source
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 679, in page_source
    return self.execute(Command.GET_PAGE_SOURCE)['value']
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
  (Session info: headless chrome=74.0.3729.157)
  (Driver info: chromedriver=74.0.3729.157 (7b16107ab85c5364cdcd0b2dea2539a1f2dc327a-refs/branch-heads/3729@{#998}),platform=Linux 4.19.66-v7+ armv7l)

以下是一些其他信息:

pip3 list |egrep "splinter|selenium"
selenium            3.141.0
splinter            0.11.0
apt-show-versions chromium-browser chromium-chromedriver python3
chromium-browser:armhf/buster 74.0.3729.157-rpt5 uptodate
chromium-chromedriver:armhf/buster 74.0.3729.157-rpt5 uptodate
python3:armhf/buster 3.7.3-1 uptodate
ls -l `which chromedriver`
-rwxr-xr-x 1 root root 10870000 Jul 10 08:27 /usr/bin/chromedriver
chromedriver --version
ChromeDriver 74.0.3729.157 (7b16107ab85c5364cdcd0b2dea2539a1f2dc327a-refs/branch-heads/3729@{#998})

要使碎片再次工作,该怎么办?

1 个答案:

答案 0 :(得分:2)

因此,在继续研究之后,我发现解决此问题的最佳方法是降级已安装的版本。谷歌搜索后,我运行apt-cache madison chromium-chromedriver chromium-browser尝试强制下载,但是在“破坏者”部分中没有以前的版本。

因此,我然后重新添加了源 deb http://archive.raspberrypi.org/debian/ stretch main/etc/apt/sources.list,然后运行apt-get update

然后我重新运行apt-cache madison chromium-chromedriver chromium-browser,给出:

chromium-chromedriver | 74.0.3729.157-rpt5 | http://archive.raspberrypi.org/debian buster/main armhf Packages
chromium-chromedriver | 72.0.3626.121-0+rpt4 | http://archive.raspberrypi.org/debian stretch/main armhf Packages
chromium-browser | 74.0.3729.157-rpt5 | http://archive.raspberrypi.org/debian buster/main armhf Packages
chromium-browser | 72.0.3626.121-0+rpt4 | http://archive.raspberrypi.org/debian stretch/main armhf Packages

经过几次尝试获取适当的依赖关系后,我运行了apt-get install chromium-chromedriver=72.0.3626.121-0+rpt4 chromium-browser=72.0.3626.121-0+rpt4 chromium-codecs-ffmpeg-extra=72.0.3626.121-0+rpt4 chromium-browser-l10n=72.0.3626.121-0+rpt4

在确认我的脚本再次运行之后,我想标记那些软件包,以使它们不会被更新apt-mark hold chromium-chromedriver chromium-browser chromium-codecs-ffmpeg-extra chromium-browser-l10n

在某个时候,我可能会再次尝试madison,看看是否有新版本,并解压软件包以查看新版本是否有效-但现在看来我还不错。