Gre*_*egg 12
呼吁geturl()结果urllib2.urlopen().geturl()"返回检索到的资源的URL,通常用于确定是否遵循重定向."
例如:
#!/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()
Run Code Online (Sandbox Code Playgroud)
输出是:
http://www.independent.co.uk/life-style/gadgets-and-tech/news/chinese-blamed-for-gmail-hacking-2292113.html
http://www.independent.co.uk/life-style/gadgets-and-tech/news/chinese-blamed-for-gmail-hacking-2292113.html
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1398 次 |
| 最近记录: |