import urllib2
import sys
content = urllib2.urlopen("http://www.higis.cn").read() #网站页面是utf-8编码的。
type = sys.getfilesystemencoding() # 关键
print content.decode("UTF-8").encode(type) # 关键
本篇博客介绍了一种使用Python的urllib2库抓取指定网址内容的方法。通过urllib2.urlopen()函数读取目标网址的内容,并利用Python内置的编码转换功能进行编码转换,最终输出网页内容。
import urllib2
import sys
content = urllib2.urlopen("http://www.higis.cn").read() #网站页面是utf-8编码的。
type = sys.getfilesystemencoding() # 关键
print content.decode("UTF-8").encode(type) # 关键

被折叠的 条评论
为什么被折叠?