0

私は OSX 10.6 と python 2.7.1 を BeautifulSoup 3.0 と feedparser 5.01 で使用しています。New York Times の 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 を使用してテストしましたが、フィードはトレースバックを引き起こしませんでした。BeautifulSoup 3.2.0 にアップグレードしてみてください。

于 2011-03-28T19:09:41.960 に答える