urllib2 javascript redirect issue
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?
First, try delivering a stern lecture to the webmaster about graceful degradation and web standards.
If that fails, then you ultimately have two options:
- 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.)
- Run the script through a JavaScript runtime, providing
window
andwindow.location
objects, and catching the assignment to itshref
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.)
精彩评论