当我尝试使用“python feedparser”时有一堆错误;在安装过程中没有抱怨。 我做了这样的事情:
import feedparser
url = "http://blogsearch.google.dk/blogsearch_feeds?" + \
"q=visitdenmark&output=atom"
f = feedparser.parse(url)
和错误:
f = feedparser.parse(url)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/feedparser.py", line 3798, in parse
feedparser.feed(data.decode('utf-8', 'replace'))
File "/usr/local/lib/python2.6/dist-packages/feedparser.py", line 1851, in feed
sgmllib.SGMLParser.feed(self, data)
File "/usr/lib/python2.6/sgmllib.py", line 104, in feed
self.goahead(0)
File "/usr/lib/python2.6/sgmllib.py", line 143, in goahead
k = self.parse_endtag(i)
File "/usr/lib/python2.6/sgmllib.py", line 320, in parse_endtag
self.finish_endtag(tag)
File "/usr/lib/python2.6/sgmllib.py", line 360, in finish_endtag
self.unknown_endtag(tag)
File "/usr/local/lib/python2.6/dist-packages/feedparser.py", line 659, in unknown_endtag
self.pop(prefix + suffix)
File "/usr/local/lib/python2.6/dist-packages/feedparser.py", line 868, in pop
mfresults = _parseMicroformats(output, self.baseuri, self.encoding)
File "/usr/local/lib/python2.6/dist-packages/feedparser.py", line 2412, in _parseMicroformats
p = _MicroformatsParser(htmlSource, baseURI, encoding)
File "/usr/local/lib/python2.6/dist-packages/feedparser.py", line 2016, in __init__
self.document = BeautifulSoup.BeautifulSoup(data)
AttributeError: 'module' object has no attribute 'BeautifulSoup'
听你说,
答案 0 :(得分:3)
AttributeError: 'module' object has no attribute 'BeautifulSoup'
看起来您需要安装BeautifulSoup:
sudo apt-get install python-beautifulsoup
PS。您已在/ usr / local中安装了一个feedparse版本。
还有一个用于feedparser的Ubuntu包:python-feedparser
。它可能不是新的,但安装它会为你绘制所有依赖项。
答案 1 :(得分:0)
你好!我在feedparser 5.0.1中没有看到这个;我的猜测是BeautifulSoup安装奇怪,或者你运行的feedparser代码已经以某种方式被修改。特别是,如果没有安装BeautifulSoup,微格式解析代码永远不应该运行,所以要达到那一点,然后发现模块中没有BeautifulSoup类,这很奇怪。
如上所述,当您运行Python解释器并只需键入
时,您会得到什么?import BeautifulSoup
print BeautifulSoup.__file__
dir(BeautifulSoup)
BeautifulSoup.BeautifulSoup
答案 2 :(得分:0)
我将分享如何修复此错误: 我在Eclipse上使用Pydev作为IDE,我犯的错误是在安装Pydev时。我为解释器选择了自动配置。这导致包含Python 2.7作为解释器,从而导致错误。