写爬虫时遇到的 &nbsp 处理

来源:互联网 发布:卓讯数据库 编辑:程序博客网 时间:2024/05/19 00:35

爬取到html内容含有 &nbsp(no-break space = non-breaking space(html中的键盘输入的多个空格会被折断为一个空格)) 时,将该内容无法GBK形式编码,为了不影响编码,应该使用方法

string.replace(u'\xa0', u' ')

其中string为待操作的字符串