Python抓取gb2312字符集网页中文乱码
来源:互联网 发布:网络公司财务 编辑:程序博客网 时间:2024/05/19 16:27
http://blog.csdn.net/asmcvc/article/details/50790623
最近在学习Python,练习用Python抓取网页内容并解析,在解析gb2312字符集网页时出现中文乱码:
UnicodeEncodeError: 'gbk' codec can't encode character u'\xbb' in position 0: illegal multibyte sequence
网上找了一大推,长篇大论啰嗦了半天都不知道在讲什么,原来Python程序员的表达能力这么差。
后来找到一个解决方案,参考:
http://www.zhetenga.com/view/python%E7%9A%84requests%E7%B1%BB%E6%8A%93%E5%8F%96%E4%B8%AD%E6%96%87%E9%A1%B5%E9%9D%A2%E5%87%BA%E7%8E%B0%E4%B9%B1%E7%A0%81-0abbaa140.html
也就是用网页中的字符编码方式重新编码一次即可:
# 使用requests库封装一个简单的通过get方式获取网页源码的函数当然 # coding: utf-8 也是要加的。
def getsource(url):
html = requests.get(url)
s = html.text.encode(html.encoding)
# print s
return s
0 0
- Python抓取gb2312字符集网页中文乱码
- Python抓取gb2312字符集网页中文乱码
- python抓取中文网页乱码
- python抓取gb2312/gbk编码网页乱码问题
- python抓取中文网页显示乱码问题
- python 网页抓取中的中文乱码问题解决
- curl抓取gb2312网页时显示乱码
- Python抓取中文网页
- Python抓取中文网页
- Python抓取中文网页
- Python抓取中文网页
- Python抓取中文网页
- Windows下Python抓取网页中文乱码解决办法
- python 解决抓取网页中的中文显示乱码问题
- nutch+mysql gb2312网页源代码中文乱码
- node js 抓取指定网页内容gb2312乱码问题解决
- Python+Requests安装及抓取网页源码中文乱码问题的解决
- 【python】网页内容抓取遭遇乱码问题
- 记录学习的点滴(Git入门)
- 生成图片二维码
- iOS CocoaPods iOS 'The sandbox is not sync with the Podfile.lock'问题解决
- 修改过的条码钩子
- storyboard中出现的问题
- Python抓取gb2312字符集网页中文乱码
- xxx is not in the sudoers file.This incident will be reported.的解决方法
- yii1.0 细小累计
- 计划任务,但可能不能运行,因为无法设置帐户信息,指定的错误是:0X80041315
- java_mail收发邮件
- 在浏览器中禁止拖动页面的元素或者拖动图片打开新的窗口
- web配置p6spy
- #342 – 将Button 和Command绑定(Binding a Button to a Command)
- ftp开发机命令使用