urllib2 JavaScript 重定向问题

发布于 2024-11-28 16:49:22 字数 495 浏览 3 评论 0原文

import urllib2,urllib

data = urllib.urlencode({"username" : "usr", "password" : "pass", "lang" : "eng", "usertype" : "cashier", "submit" : "Enter"})
req = urllib2.Request("https://website/index.php", data)
opener = urllib2.build_opener()
response = opener.open(req)
the_page = response.read()
print the_page

输出:

<script type="text/javascript">window.location.href = "/h383/list.php";</script>

所以我想访问list.php,有什么建议吗?

import urllib2,urllib

data = urllib.urlencode({"username" : "usr", "password" : "pass", "lang" : "eng", "usertype" : "cashier", "submit" : "Enter"})
req = urllib2.Request("https://website/index.php", data)
opener = urllib2.build_opener()
response = opener.open(req)
the_page = response.read()
print the_page

OUTPUT:

<script type="text/javascript">window.location.href = "/h383/list.php";</script>

So I want to reach list.php any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

平生欢 2024-12-05 16:49:22

首先,尝试向网站管理员进行关于优雅降级和网络标准的严厉教训。

如果失败,那么您最终有两个选择:

  1. 使用正则表达式提取重定向位置。 (优点:这很简单。缺点:如果重定向 URL 是使用 JavaScript 构建的,而不是显示为单个字符串文字,则这将不起作用。此外,脚本中的微小更改 - 甚至添加空格 -可能会破坏您的表达式。)
  2. 通过 JavaScript 运行时运行脚本,提供 windowwindow.location 对象,并捕获对其 href 的赋值代码>属性。 (优点:这将允许 JS 构建的 URL 工作,并且是相当面向未来的。缺点:这可能是过度设计,并且不是一个简单的任务。)

First, try delivering a stern lecture to the webmaster about graceful degradation and web standards.

If that fails, then you ultimately have two options:

  1. Extract the redirection location using a regular expression. (Pro: This is easy. Cons: This won't work if the redirection URL is built using JavaScript, as opposed to showing up as a single string literal. Additionally, minute changes in the script -- even the addition of whitespace -- are likely to break your expression.)
  2. Run the script through a JavaScript runtime, providing window and window.location objects, and catching the assignment to its href property. (Pros: This will allow for JS-built URLs to work, and is fairly future-proof. Cons: This is probably over-engineering, and won't be a simple task.)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文