我正在使用 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' codec can't decode byte 0x80 in position 107: invalid start byte
我曾尝试使用 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