python feedparser 安装错误

0 投票
3 回答
4604 浏览
提问于 2025-04-16 11:35

我在使用“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'

期待你的回复,

3 个回答

0

我来分享一下我是怎么解决这个错误的:

我在Eclipse上使用Pydev作为开发工具,出错的原因是在安装Pydev的时候。我选择了自动配置解释器,这样就把Python 2.7当成了解释器,结果就导致了这个错误。

0

你好!我在feedparser 5.0.1中没有看到这个问题;我猜可能是BeautifulSoup的安装有点问题,或者你运行的feedparser代码被修改过。特别是,如果没有安装BeautifulSoup,微格式解析的代码是不会运行的,所以如果到了那一步却发现模块里没有BeautifulSoup这个类,那就有点奇怪了。

如上所述,当你运行Python解释器并简单输入以下内容时,你会得到什么呢?

import BeautifulSoup
print BeautifulSoup.__file__
dir(BeautifulSoup)
BeautifulSoup.BeautifulSoup
3
AttributeError: 'module' object has no attribute 'BeautifulSoup'

看起来你需要安装BeautifulSoup这个库:

sudo apt-get install python-beautifulsoup

另外,你在/usr/local安装了一个版本的feedparse。 Ubuntu也有一个叫做python-feedparser的包。虽然这个包可能不是最新的,但安装它会自动帮你处理所有需要的依赖项。

撰写回答