0

我将 OSX 10.6 和 python 2.7.1 与 BeautifulSoup 3.0 和 feedparser 5.01 一起使用。我正在尝试解析纽约时报的 RSS 提要,它会验证,而 Beautiful Soup 本身会很高兴地解析。

产生错误的最小代码是:

import feedparser
from BeautifulSoup import BeautifulSoup


feed = feedparser.parse("http://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml")
  • 如果我使用 url 或使用 urllib2.urlopen 获取内容,它会失败。
  • 我也尝试过字符集检测器。

错误块是:

 /Users/user/Source/python/feed/BeautifulSoup.py:1553: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif data[:3] == '\xef\xbb\xbf':
/Users/user/Source/python/feed/BeautifulSoup.py:1556: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif data[:4] == '\x00\x00\xfe\xff':
/Users/user/Source/python/feed/BeautifulSoup.py:1559: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif data[:4] == '\xff\xfe\x00\x00':
Traceback (most recent call last):
  File "parse.py", line 5, in <module>
    feed = feedparser.parse("http://www.nytimes.com/services/xml/rss/nyt/GlobalHome.xml")
  File "/Users/user/Source/python/feed/feedparser.py", line 3822, in parse
    feedparser.feed(data.decode('utf-8', 'replace'))
  File "/Users/user/Source/python/feed/feedparser.py", line 1851, in feed
    sgmllib.SGMLParser.feed(self, data)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sgmllib.py", line 104, in feed
    self.goahead(0)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sgmllib.py", line 143, in goahead
    k = self.parse_endtag(i)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sgmllib.py", line 320, in parse_endtag
    self.finish_endtag(tag)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sgmllib.py", line 360, in finish_endtag
    self.unknown_endtag(tag)
  File "/Users/user/Source/python/feed/feedparser.py", line 657, in unknown_endtag
    method()
  File "/Users/user/Source/python/feed/feedparser.py", line 1545, in _end_description
    value = self.popContent('description')
  File "/Users/user/Source/python/feed/feedparser.py", line 961, in popContent
    value = self.pop(tag)
  File "/Users/user/Source/python/feed/feedparser.py", line 868, in pop
    mfresults = _parseMicroformats(output, self.baseuri, self.encoding)
  File "/Users/user/Source/python/feed/feedparser.py", line 2420, in _parseMicroformats
    p = _MicroformatsParser(htmlSource, baseURI, encoding)
  File "/Users/user/Source/python/feed/feedparser.py", line 2024, in __init__
    self.document = BeautifulSoup.BeautifulSoup(data)
  File "/Users/user/Source/python/feed/BeautifulSoup.py", line 1228, in __init__
    BeautifulStoneSoup.__init__(self, *args, **kwargs)
  File "/Users/user/Source/python/feed/BeautifulSoup.py", line 892, in __init__
    self._feed()
  File "/Users/user/Source/python/feed/BeautifulSoup.py", line 917, in _feed
    SGMLParser.feed(self, markup)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sgmllib.py", line 103, in feed
    self.rawdata = self.rawdata + data
TypeError: cannot concatenate 'str' and 'NoneType' objects

我非常感谢任何建议。

4

1 回答 1

1

我使用 Python 2.7.1、feedparser 5.0.1 和 BeautifulSoup 3.2.0 进行了测试,但 feed 没有引起回溯。尝试升级到 BeautifulSoup 3.2.0。

于 2011-03-28T19:09:41.960 回答