英文:
Selenium get current URL as soon as the website is redirected
问题
我正在尝试在标签页的URL更改时立即获取网站的URL。但是当前脚本会等待页面加载,然后才提供URL。我想要实时获取URL,即使在页面加载之前也能获取。
iniurl = driver.current_url
一些自动化步骤
while url_change:
if driver.current_url != ini_url:
url_change = False
print(driver.current_url)
driver.quit()
目前这个方法非常慢,不是实时的。
英文:
I am trying to get the URL of a website as soon as the URL on tab changes. But currently the script waits for the page to load and then gives me the URL. I want to get the URL in real time even before the page gets loaded.
iniurl = driver.current_url
SOME AUTOMATION STEPS
while url_change:
if driver.current_url != ini_url:
url_change = False
print(driver.current_url)
driver.quit()
Currently this is very slow, not realtime.
答案1
得分: 0
我在一些测试之后终于找到了答案。这是实时的,不会等待页面加载,因此比使用页面加载策略='eager'更快。
iniurl = driver.current_url
一些自动化步骤
while url_change:
if driver.execute_script("return window.location.href") != ini_url:
url_change = False
print(driver.current_url)
driver.quit()
英文:
I found an answer to this finally after some testing. This is in real time and does not wait for page to load so its faster than using the page load strategy = 'eager'
iniurl = driver.current_url
SOME AUTOMATION STEPS
while url_change:
if driver.execute_script("return window.location.href") != ini_url:
url_change = False
print(driver.current_url)
driver.quit()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论