Selenium页面加载策略,不等待初始加载

huangapple go评论83阅读模式
英文:

Selenium page load strategy to not wait for initial load

问题

根据文档,加载策略的选项有normal(正常)、eager(急切)和none(无)。none似乎是对于驱动程序阻塞时间最少的选项,但仍然需要等待页面的初始加载才能转到不同的URL。我想在脚本执行期间的某个时刻,点击一个链接,跳转到另一个URL,而在初始加载过程中仍然可以转到不同的URL。是否有方法让驱动程序在此期间不被阻塞,甚至有解决方法吗?

英文:

According to the docs, the options for the load strategy are normal, eager, and none. none seems to be the one with the least blocking time for the driver but it still waits for an initial load of the page before I can go to a different url. I would like to at some point during the script, click on a link that goes somewhere, and while it is still initially loading go to a different url. Is there a way to get the driver to not get blocked during that time or even a workaround?

答案1

得分: 1

以下是要翻译的内容:

这是如何使用Python Selenium正确设置page_load_strategy"none"的方法:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service()
options = webdriver.ChromeOptions()
options.page_load_strategy = "none"
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()

请注意,您需要使用"none",而不是None,这是一个常见的错误。

选项有"none""eager""normal"

英文:

This is how to properly set the page_load_strategy to "none" with Python Selenium:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service()
options = webdriver.ChromeOptions()
options.page_load_strategy = "none"
driver = webdriver.Chrome(service=service, options=options)
# ...
driver.quit()

Note that you need to use "none", NOT None, which is a common mistake.

Options are "none", "eager", and "normal".

huangapple
  • 本文由 发表于 2023年6月25日 19:38:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76550206.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定