惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
Lohrmann on Cybersecurity
S
Secure Thoughts
I
Intezer
Forbes - Security
Forbes - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
H
Help Net Security
IT之家
IT之家
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
宝玉的分享
宝玉的分享
S
Securelist
T
The Exploit Database - CXSecurity.com
博客园 - 叶小钗
Security Latest
Security Latest
The Cloudflare Blog
Jina AI
Jina AI
T
Tenable Blog
J
Java Code Geeks
G
GRAHAM CLULEY
C
CERT Recently Published Vulnerability Notes
SecWiki News
SecWiki News
AI
AI
博客园 - 聂微东
S
Schneier on Security
博客园_首页
爱范儿
爱范儿
有赞技术团队
有赞技术团队
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 【当耐特】
T
Threatpost
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell
Recent Announcements
Recent Announcements
W
WeLiveSecurity
M
MIT News - Artificial intelligence
H
Hackread – Cybersecurity News, Data Breaches, AI and More
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
T
Threat Research - Cisco Blogs
S
Security Affairs
T
Tor Project blog
T
Tailwind CSS Blog
N
News | PayPal Newsroom
C
CXSECURITY Database RSS Feed - CXSecurity.com
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
The Register - Security
The Register - Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security

博客园 - 夏日微风

mysql备份和恢复命令 使用setuptools自动安装python模块 Python的MySQL库 php2python Python中文支持小结 WordPress安装步骤 centos 5.6 升级php到5.3 vsftp 的默认目录位置 Linux Develop Notes Linux Command Notes C#格式化数值结果表 - 夏日微风 - 博客园 证监会新年联欢会节目单(征求意见稿) 在.NET中打开ODBC“选择数据源”对话框 命案十三宗 看港剧,学穿衣 - 欧阳震华 看港剧,学穿衣 - 张家辉 - 胖矮个 看港剧,学穿衣 - 林保怡 - 小矮个 看港剧,学穿衣 - 罗嘉良 - 土蛋 看港剧,学穿衣 - 苏永康 - 斯文丑男
urllib2下载时判断网页编码
夏日微风 · 2011-07-06 · via 博客园 - 夏日微风

原文网址:http://stackoverflow.com/questions/1495627/how-to-download-any-webpage-with-correct-charset-in-python

fp = urllib2.urlopen(request)
charset = fp.headers.getparam('charset')

对于中文网页,charset可能的值有:UTF-8, GB2312

不过urllib2有点问题,UTF-8能正确判断,但有些GB2312的网页,不能正确判断,而是返回None,例如 http://news.sina.com.cn 这点需要注意

--------------------------------------------------------------------------------

另外一个方法是用 chardet,http://chardet.feedparser.org/

但chardet性能有问题。