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

推荐订阅源

D
Docker
AI
AI
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
The Cloudflare Blog
Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
博客园 - 【当耐特】
V
Visual Studio Blog
博客园 - Franky
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
Intezer
C
Cybersecurity and Infrastructure Security Agency CISA
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
SegmentFault 最新的问题
腾讯CDC
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
Webroot Blog
Webroot Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
T
Tor Project blog
WordPress大学
WordPress大学
雷峰网
雷峰网
J
Java Code Geeks
GbyAI
GbyAI
Recorded Future
Recorded Future
F
Full Disclosure
Cisco Talos Blog
Cisco Talos Blog
S
Secure Thoughts
I
InfoQ
量子位
Forbes - Security
Forbes - Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threatpost
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
Attack and Defense Labs
Attack and Defense Labs
爱范儿
爱范儿
N
News and Events Feed by Topic
V
Vulnerabilities – Threatpost
L
LINUX DO - 最新话题
A
Arctic Wolf
S
Security Affairs

博客园 - 夏日微风

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性能有问题。