python selenium:可以取消driver.get()上的重定向吗? [英] python selenium: possible to cancel redirect on driver.get()?

查看:80
本文介绍了python selenium:可以取消driver.get()上的重定向吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法阻止 url 重定向?

Is there a way to stop a url from redirecting?

driver.get('http://loginrequired.com')

这会将我重定向到另一个页面,但我希望它留在该页面上而不默认重定向.

This redirects me to another page but I want it to stay on that page without redirecting by default.

推荐答案

用户称之为重定向"的方法有两种:通常发生:

There are two ways that what users call "redirection" typically happens:

  1. 您加载一个页面,该页面加载了一些 JavaScript 代码,这些代码执行测试并决定加载不同的页面.在某些浏览器中,可以通过按 ESCAPE 键来中断此过程.Selenium 可以发送 ESCAPE 密钥.

  1. You load a page and the page loads some JavaScript code which performs a test and decides to load a different page. This process can be interrupted in some browsers by hitting the ESCAPE key. Selenium can send an ESCAPE key.

但是,这种重定向可能发生在之前 Selenium 将控制权交还给您的脚本.它是否适用于任何特定情况取决于正在加载的页面.

However, this redirection could happen before Selenium gives control back to your script. Whether it would work in any specific case depends on the page being loaded.

您加载页面并从服务器获得 HTTP 3xx(301、303、304 等)响应.用户没有机会在其浏览器中中断这些重定向,因此 Selenium 不提供中断或阻止它们的方法.

You load a page and get an HTTP 3xx (301, 303, 304, etc.) response from the server. There are no opportunities for users to interrupt these redirections in their browser, so Selenium does not provide the means to interrupt or prevent them.

因此在 Selenium 中没有万无一失的方法来防止重定向.

So there is no surefire way to prevent a redirection in Selenium.

这篇关于python selenium:可以取消driver.get()上的重定向吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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