[英]ChromeDriver is too slower than GeckoDriver on the first page query through Selenium and Python
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). 我有最新版本的驱动程序(chromedriver = 2.44.609551),硒包(3.141.0)和(无头chrome = 70.0.3538.110)。 (on windows)
(在Windows上)
I am opening multiple windows with the browser. 我正在使用浏览器打开多个窗口。 Using firefox, my script is always fast.
使用firefox,我的脚本总是很快。 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.
但是在chrome上,切换到窗口(已加载页面)后,当我尝试从浏览器获取任何内容(例如driver.page_source或任何find_element)时,出现了4s延迟。
Am I doing something wrong? 难道我做错了什么?
[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
If i switch driver.page_source
with driver.find_elements_by_class_name('class_name')
, the first one will be always slow. 如果我用
driver.find_elements_by_class_name('class_name')
切换driver.page_source
,则第一个总是很慢。
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. 正如您在问题中提到的那样, 此时GeckoDriver / Firefox组合的速度比ChromeDriver / Chrome快,值得一提的是,不同的浏览器以不同的方式呈现HTML DOM 。
You can find a detailed discussion in Chrome & Firefox on Windows vs Linux (selenium) 您可以在Windows和Linux(硒)上的Chrome和Firefox中找到详细的讨论
Moreover, there had been a lot of discussion going around about the unpredictable CPU and Memory Consumption by Chrome Headless sessions. 此外,关于Chrome Headless会话无法预测的CPU和内存消耗的讨论也很多。
As per the discussion Building headless for minimum cpu+mem usage the CPU + Memory usage can be optimized by: 根据讨论, 构建最低的cpu + mem使用率 ,可以通过以下方式优化CPU +内存使用率:
requestAnimationFrame
and animation triggers
) but we expect there are a lot of CPU savings to be had here. requestAnimationFrame
和animation triggers
),但我们希望在此节省大量CPU。 An usage can be: 用法可以是:
$ headless_shell --remote-debugging-port=9222 --trace-startup=*,disabled-by-default-memory-infra http://www.chromium.org
Chromium is always going to use as much resources as are available to it. 铬将始终使用尽可能多的资源。 If you want to effectively limit it's utilization, you should look into using cgroups
如果要有效限制其利用率,则应考虑使用cgroups
You can find a detailed discussion in Limit chrome headless CPU and memory usage 您可以在限制Chrome无头CPU和内存使用情况中找到详细的讨论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.