2011-02-10 84 views
0

当我尝试使用“python feedparser”时出现了一堆错误;而在安装过程中没有抱怨。 我做一些事情是这样的: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

“导入BeautifulSoup”在python控制台中工作吗? – 2011-02-10 17:06:36

回答

3
AttributeError: 'module' object has no attribute 'BeautifulSoup' 

看起来你需要安装BeautifulSoup:

sudo apt-get install python-beautifulsoup 

PS。您已在/ usr/local中安装了一个feedparse版本。 还有一个用于feedparser的Ubuntu包:python-feedparser。它可能不是新的,但安装它会吸引你的所有依赖。

+0

谢谢你的回复, – user702846 2011-02-10 22:15:09

0

你好!我在feedparser 5.0.1中没有看到这个;我的猜测是BeautifulSoup的安装很奇怪,或者您正在运行的feedparser代码已经以某种方式进行了修改。特别是,如果没有安装BeautifulSoup,则微格式解析代码应该永远不会运行,所以为了达到这一点,然后发现模块中没有BeautifulSoup类是很奇怪的。

如上所述,就当你运行Python解释器,你会得到什么,简单地键入

import BeautifulSoup 
print BeautifulSoup.__file__ 
dir(BeautifulSoup) 
BeautifulSoup.BeautifulSoup 
0

我将分享我是如何解决这个错误: 我使用Pydev的基于Eclipse的IDE和错误,我是在Pydev的安装过程中完成的。我选择了自动配置解释器。这导致了包含Python 2.7作为解释器,从而导致了错误。