栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

不要等待在Python中使用Selenium加载页面

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

不要等待在Python中使用Selenium加载页面

ChromeDriver 77.0 (支持Chrome 77版本)现在支持

eager
作为 pageLoadStrategy

已解决的问题1902:支持优先页面加载策略[Pri-2]


如您所提,

click on elements and scrape data before the page has fullyloaded
在这种情况下,我们可以利用属性
pageLoadStrategy
。当Selenium默认加载页面/ URL时,它将遵循默认配置,
pageLoadStrategy
设置为
normal
。Selenium可以从不同的代码开始执行下一行代码
documentreadiness state
。目前,Selenium支持3种不同的功能
document readiness state

,我们可以通过
pageLoadStrategy
以下方式进行配置:

  1. none
    (未定义)
  2. eager
    (页面变为交互式)
  3. normal
    (完整的页面加载)

这是配置代码的代码块

pageLoadStrategy

from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiesbinary = r'C:Program FilesMozilla Firefoxfirefox.exe'caps = DesiredCapabilities().FIREFOX# caps["pageLoadStrategy"] = "normal"  #  completecaps["pageLoadStrategy"] = "eager"  #  interactive# caps["pageLoadStrategy"] = "none"   #  undefineddriver = webdriver.Firefox(capabilities=caps, firefox_binary=binary, executable_path="C:\Utility\BrowserDrivers\geckodriver.exe")driver.get("https://google.com")


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/662373.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号