首页 > 编程语言 > 详细

python urllib2 中文乱码解决

时间:2016-03-11 15:38:48      阅读:283      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!