问题描述
我正在尝试将新的 (2016) headless 版本的 Chromium 与 Selenium/ChromeDriver 一起使用(过去,我将 Firefox 与 xfvb 一起使用,但这有望更好).
I am trying to use the new (2016) headless version of Chromium with Selenium/ChromeDriver (In the past, I used Firefox with xfvb but this promises to be much better).
我根据我找到的说明从源代码编译了一个无头版本的 Chromium(我没有找到任何预构建的二进制文件)here 然后我使用以下代码通过 Selenium 启动它:
I have compiled a headless version of Chromium from sources (I did not find any pre-built binaries) based on the instructions I found here and then I used the following code to launch it through Selenium:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
l_option = Options()
l_option.add_argument('headless')
l_option.add_argument('disable-notifications')
l_option.binary_location = '/home/fi11222/Headless_Chromium/headless_shell'
l_driver = webdriver.Chrome(chrome_options=l_option)
相同的代码适用于标准铬(如果我删除 binary.location 选项)
The same code works with the standard chromium (if I remove the binary.location option)
但是,我收到以下错误:
As is, however, I get the following error:
selenium.common.exceptions.WebDriverException: Message: unknown error: unrecognized Chrome version: HeadlessChrome/59.0.3032.0
(Driver info: chromedriver=2.27.440175 (9bc1d90b8bfa4dd181fbbf769a5eb5e575574320),platform=Linux 4.4.0-53-generic x86_64)
显然,无头 chromium 二进制文件是使用 ChromeDriver 无法识别的版本 ID 编译的.救命!!
Apparently, the headless chromium binary is compiled with a version ID that ChromeDriver does not recognize. Help !!
环境:
- 编译:Ubuntu 16.04 服务器
- Selenium 执行:Linux Mint 18.1
推荐答案
ChromeHeadless 被 chromedriver 识别,因为 此补丁(在您发布消息后创建),仅在 chromedriver 2.29(2017 年 4 月发布)之后可用.确保您在 PATH 中具有此 chromedriver 可执行文件,并且 Selenium 正在选择它,而不是您可能拥有的任何其他 chromedriver.
ChromeHeadless is recognized by chromedriver since this patch (created after you have post your message), which is only available since chromedriver 2.29 (released in April 2017). Make sure that you have this chromedriver executable available in PATH and that Selenium is picking it instead of any other chromedriver you might have available.
另外,请注意 - 根据 无头 Chrome 文档 - 你需要再传递两个标志:
Also, please note that - according to headless Chrome documentation - you need to pass two more flags:
l_option.add_argument('remote-debugging-port=9222')
l_option.add_argument('disable-gpu')
至于无头 Chrome 的预构建二进制文件 - 该选项自 Chrome 57 起可用,因此当前通过官方 Google 存储库分发的所有版本都支持它(即稳定的 Chrome 58 和不稳定的 Chrome 59).它是 Chrome 59 的亮点,所以在功能稳定之前,请期待一些粗糙的边缘.
As for pre-built binaries of headless Chrome - that option is available since Chrome 57, so it is supported by all versions currently distributed through official Google repository (i.e. stable Chrome 58 and unstable Chrome 59). It is highlight of Chrome 59, so expect some rough edges until feature is stabilized.
这篇关于Selenium ChromeDriver 无法识别新编译的 Headless Chromium (Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)