码迷,mamicode.com
首页 > 编程语言 > 详细

python urllib2 中文乱码解决

时间:2016-03-11 15:41:08      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:

 

import urllib2
import re
url = ‘http://192.168.80.128/‘
charset_reg =r‘<meta.*charset="?([\w|-]*)"?\s*/?>‘
patten = re.compile(charset_reg)
req = urllib2.Request(url)
html = urllib2.urlopen(req).read()
code = patten.search(html).group(1)
print code
print html.decode(code)

  

 

正则表达式:  <meta.*charset="?([\w|-]*)"?\s*/?>

 

亲测能匹配很多网页!做个笔记在这

=====================================================

seo:

 python urllib2 中文乱码解决

python urllib2 中文乱码解决

python urllib2 中文乱码解决

python urllib2 中文乱码解决

网页编码正则表达式

网页编码正则表达式

网页编码正则表达式

 

python urllib2 中文乱码解决

标签:

原文地址:http://www.cnblogs.com/Hslim/p/5265777.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!