“渴望"适用于Python的Chromedriver Selenium的页面加载策略变通办法 [英] "Eager" Page Load Strategy workaround for Chromedriver Selenium in Python

查看:398
本文介绍了“渴望"适用于Python的Chromedriver Selenium的页面加载策略变通办法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加快硒页面的加载时间,因为除了HTML之外,我不需要任何其他东西(我正在尝试使用BeautifulSoup抓取所有链接).使用PageLoadStrategy.NONE无法删除所有链接,并且Chrome不再支持PageLoadStrategy.EAGER.有谁知道在python中获取PageLoadStrategy.EAGER的解决方法?

I want to speed up the loading time for pages on selenium because I don't need anything more than the HTML (I am trying to scrape all the links using BeautifulSoup). Using PageLoadStrategy.NONE doesn't work to scrape all the links, and Chrome no longer supports PageLoadStrategy.EAGER. Does anyone know of a workaround to get PageLoadStrategy.EAGER in python?

推荐答案

ChromeDriver 独立服务器,它实现了 W3C标准 .目前 ChromeDriver 可用于Android上的Chrome和台式机(Mac,Linux,Windows和ChromeOS)上的Chrome.

ChromeDriver is the standalone server which implements WebDriver's wire protocol for Chromium. Chrome and Chromium are still in the process of implementing and moving to the W3C standard. Currently ChromeDriver is available for Chrome on Android and Chrome on Desktop (Mac, Linux, Windows and ChromeOS).

按照当前> WebDriver W3C编辑器草案 下表是将 pageLoadStrategy 功能关键字链接到页面加载策略状态的页面加载策略表,并显示了对应的文档准备状态对此:

As per the current WebDriver W3C Editor's Draft The following is the table of page load strategies that links the pageLoadStrategy capability keyword to a page loading strategy state, and shows which document readiness state that corresponds to it:

但是,如果您观察到 ChromeDriver 的当前实现,则

However, if you observe the current implementation of of ChromeDriver, the Chrome DevTools does takes into account the following document.readyStates:

  • document.readyState == 'complete'
  • document.readyState == 'interactive'

以下是相关日志示例:

[1517231304.270][DEBUG]: DEVTOOLS COMMAND Runtime.evaluate (id=11) {
   "expression": "var isLoaded = document.readyState == 'complete' ||    document.readyState == 'interactive';if (isLoaded) {  var frame = document.createElement('iframe');  frame.name = 'chromedriver dummy frame'; ..."
}

根据 WebDriver状态,您会发现 WebDriver命令的列表及其在 ChromeDriver 中的当前支持(基于 WebDriver规范 .一旦从各个方面实现了完成后, PageLoadStrategy.EAGER 势必会存在于 Chrome驱动程序中.

As per WebDriver Status you will find the list of all WebDriver commands and their current support in ChromeDriver based on what is in the WebDriver Specification. Once the implementation are completed from all aspects PageLoadStrategy.EAGER is bound to be functionally present within Chrome Driver.

这篇关于“渴望"适用于Python的Chromedriver Selenium的页面加载策略变通办法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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