擅长:python、mysql、java
<p>对<code>urllib2.urlopen()</code>的结果调用<code>geturl()</code>。<code>geturl()</code>“返回检索到的资源的URL,通常用于确定是否遵循了重定向。”</p>
<p>例如:</p>
<pre><code>#!/usr/bin/env python
# coding: utf-8
import urllib2
url1 = 'http://www.independent.co.uk/life-style/gadgets-and-tech/news/chinese-blamed-for-gmail-hacking-2292113.html'
url2 = 'http://www.independent.co.uk/life-style/gadgets-and-tech/news/2292113.html'
for url in [url1, url2]:
result = urllib2.urlopen(url)
print result.geturl()
</code></pre>
<p>输出为:</p>
^{pr2}$