Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python如何捕获302重定向url_Python_Url_Redirect_Capture - Fatal编程技术网

python如何捕获302重定向url

python如何捕获302重定向url,python,url,redirect,capture,Python,Url,Redirect,Capture,我尝试从web获取数据,但页面使用302重定向 如何使用python获取真正的url?看看本系列文章。它非常详细地解释了您的整个问题、示例代码和所有内容。看看本系列文章。它非常详细地解释了您的整个问题、示例代码和所有内容。您当前使用的是什么?urllib和urllib2都应该自动处理它: page = urllib.urlopen('http://mrozekma.com/302test.php') >>> print page.geturl() # This will s

我尝试从web获取数据,但页面使用302重定向
如何使用python获取真正的url?

看看本系列文章。它非常详细地解释了您的整个问题、示例代码和所有内容。

看看本系列文章。它非常详细地解释了您的整个问题、示例代码和所有内容。

您当前使用的是什么?urllib和urllib2都应该自动处理它:

page = urllib.urlopen('http://mrozekma.com/302test.php')
>>> print page.geturl()   # This will show the redirected-to URL
http://mrozekma.com/302test.php?success
>>> print page.readlines()
['Success']

您目前正在使用什么?urllib和urllib2都应该自动处理它:

page = urllib.urlopen('http://mrozekma.com/302test.php')
>>> print page.geturl()   # This will show the redirected-to URL
http://mrozekma.com/302test.php?success
>>> print page.readlines()
['Success']

如果您使用的是http.client.HTTPConnection3.x或httplib.HTTPConnection2.x,只需获取位置头:

response.getheader('Location')

我知道这至少在craigslist.org上有效,如果您使用的是http.client.HTTPConnection3.x或httplib.HTTPConnection2.x,只需获取位置标题:

response.getheader('Location')
我知道这至少在craigslist.org上有效