英文:
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"
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论