在通过Selenium和Python进行首页查询时,ChromeDriver的速度比GeckoDriver的速度慢 [英] ChromeDriver is too slower than GeckoDriver on the first page query through Selenium and Python

查看:253
本文介绍了在通过Selenium和Python进行首页查询时,ChromeDriver的速度比GeckoDriver的速度慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有最新版本的驱动程序(chromedriver = 2.44.609551),硒包(3.141.0)和(无头chrome = 70.0.3538.110).(在Windows上)

I have the latest version of the drivers (chromedriver=2.44.609551), selenium package(3.141.0) and the (headless chrome=70.0.3538.110). (on windows)

我正在使用浏览器打开多个窗口.使用firefox,我的脚本总是很快.但是在chrome上,切换到窗口(已加载页面)后,当我尝试从浏览器获取任何内容(例如driver.page_source或任何find_element)时,出现了4s延迟.

I am opening multiple windows with the browser. Using firefox, my script is always fast. But on chrome, after switching to a window (with the page already loaded), when I try to get anything from the browser (like driver.page_source or any find_element), I get a 4s-ish delay.

我做错什么了吗?

[driver.execute_script('window.open(arguments[0]);', url) for url in urls]
for window in driver.window_handles[1:]:
    driver.switch_to.window(window)
    driver.page_source                                #it takes 4s here
    driver.find_elements_by_class_name('class_name')  #regular speed here (fast)
    break

如果我用 driver.find_elements_by_class_name('class_name')切换 driver.page_source ,第一个总是很慢.

If i switch driver.page_source with driver.find_elements_by_class_name('class_name'), the first one will be always slow.

推荐答案

正如您在问题中提到的, GeckoDriver / Firefox 组合要比 ChromeDriver 快em>/ Chrome 在这一点上,值得一提的是,不同的浏览器呈现了

As you mentioned in your question GeckoDriver / Firefox combination is faster then ChromeDriver / Chrome at this point it is worth to mention that diferent browsers render the HTML DOM in a different way.

您可以在 Chrome&Windows和Linux(硒)上的Firefox

此外,通过 Chrome Headless 会议,围绕不可预测的 CPU 内存消耗进行了大量讨论.

Moreover, there had been a lot of discussion going around about the unpredictable CPU and Memory Consumption by Chrome Headless sessions.

根据讨论情况为...建立无头最低CPU +内存使用量 CPU +内存使用量可以通过以下方式优化:

As per the discussion Building headless for minimum cpu+mem usage the CPU + Memory usage can be optimized by:

  • Using either a custom proxy or C++ ProtocolHandlers you could return stub 1x1 pixel images or even block them entirely.
  • Chromium Team is working on adding a programmatic control over when frames are produced. Currently headless chrome is still trying to render at 60 fps which is rather wasteful. Many pages do need a few frames (maybe 10-20 fps) to render properly (due to usage of requestAnimationFrame and animation triggers) but we expect there are a lot of CPU savings to be had here.
  • MemoryInfra should help you determine which component is the biggest consumer of memory in your setup.
  • An usage can be:

$ headless_shell --remote-debugging-port=9222 --trace-startup=*,disabled-by-default-memory-infra http://www.chromium.org

  • 铬总是将使用尽可能多的资源.如果要有效地限制其利用率,则应考虑使用您可以在限制chrome无头CPU和内存使用率中找到详细的讨论

    这篇关于在通过Selenium和Python进行首页查询时,ChromeDriver的速度比GeckoDriver的速度慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆