使用BeautifulSoup出现中文编码异常的解决办法 Denis Huang 2015-08-26 15:26 源代码 UnicodeEncodeError: 'gbk' codec can't encode character u'xd0' in position 0: 几经波折,我才发现,问题都在html源串上,我的解决办法是: 传给BeautifulSoup的html先进行unicode编码。 html=urllib2.urlopen(url).read() sp=BeautifulSoup(html.decode('gbk').encode('utf-8')) 后面再getText()时就没有乱码问题了 Comments
Comments