UnicodeDecodeError:'utf8'编解码器无法解码位置21中的字节0x80:无效的起始字节

时间:2013-06-10 07:38:08

标签: python beautifulsoup

我正在使用BeautifulSoup来关闭http://www.reuters.com/article/2012/04/01/net-us-foxconn-idUSBRE83004E20120401

的文章
url="http://www.reuters.com/article/2012/10/19/us-yahoo-korea-idUSBRE89I0EY20121019"
source = urllib2.urlopen(url)
soup = BeautifulSoup(source)

但收到错误 UnicodeDecodeError:'utf8'编解码器无法解码107位的字节0x80:无效的起始字节

我曾尝试使用soup.encode(['windows-1252','ascii','iso-8859']),但首先,汤甚至无法创建。

有没有人有任何分享的提示?

错误回溯,如果有帮助:

Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
parseReuters()
File "C:\Users\name\Desktop\test.py", line 39, in parseReuters
soup = BeautifulSoup(source)
File "C:\Python27\lib\site-packages\bs4\__init__.py", line 172, in __init__
self._feed()
File "C:\Python27\lib\site-packages\bs4\__init__.py", line 185, in _feed
self.builder.feed(self.markup)
File "C:\Python27\lib\site-packages\bs4\builder\_lxml.py", line 195, in feed
self.parser.close()
File "parser.pxi", line 1209, in lxml.etree._FeedParser.close (src\lxml\lxml.etree.c:90597)
File "parsertarget.pxi", line 142, in lxml.etree._TargetParserContext._handleParseResult (src\lxml\lxml.etree.c:99984)
File "parsertarget.pxi", line 130, in lxml.etree._TargetParserContext._handleParseResult (src\lxml\lxml.etree.c:99807)
File "lxml.etree.pyx", line 294, in lxml.etree._ExceptionContext._raise_if_stored (src\lxml\lxml.etree.c:9383)
File "saxparser.pxi", line 259, in lxml.etree._handleSaxData (src\lxml\lxml.etree.c:95945)
UnicodeDecodeError: 'utf8' codec can't decode byte 0x80 in position 0: invalid start byte

0 个答案:

没有答案