我使用urllib2.urlopen
方法打开一个网址并获取网页的标记。其中一些站点使用301/302重定向来重定向我。我想知道我被重定向到的最终URL。我怎么才能得到这个呢?
发布于 2010-08-24 20:16:35
urllib2.urlopen
的返回值有一个geturl()
方法,它应该返回实际的(即最后一个重定向的) url。
发布于 2015-07-11 15:22:12
例如:urllib2.urlopen('ORIGINAL LINK').geturl()
urllib2.urlopen(urllib2.Request('ORIGINAL LINK')).geturl()
发布于 2012-07-24 02:00:50
您可以将HttpLib2
与follow_all_redirects = True
一起使用,并从响应头中获取content-location
。有关示例,请参阅my answer to 'httplib is not getting all the redirect codes'。
https://stackoverflow.com/questions/3556266
复制相似问题