【发布时间】:2011-11-01 18:23:19
【问题描述】:
我有一个要获取的 url,它提供了一个 HTTP 303 重定向:
import urllib2 as web
import sys
url='http://sample.com'
try: handle=web.urlopen(url)
except web.HTTPError, e:
print e.code
sys.exit(1)
data=handle.read()
print 'Result :'
print data
所以,上面的代码打印了303,结果是一个303重定向。
我希望它遵循重定向并获取目标的 HTML。
请帮忙..
编辑:
curl -I http://my303redirecturl.com/
HTTP/1.1 303 See Other
Date: Tue, 23 Aug 2011 04:53:53 IST
Server: Mule Core/3.1.2
Expires: Tue, 23 Aug 2011 04:53:53 IST
http.status: 303
Content-Type: application/json
MULE_ENCODING: UTF-8
Content-Length: 0
Connection: close
这会有帮助吗?
【问题讨论】:
-
您使用的是哪个 Python 版本?
-
Python 版本 = Python 2.6.6
-
使用 cPython 2.6.7,我无法重现该问题。您可以尝试我的答案中的演示代码并报告给您的结果吗?
标签: python redirect urllib2 http-error