0

当我尝试使用“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'

收到你的回复,

4

3 回答 3

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

看起来您需要安装 BeautifulSoup:

sudo apt-get install python-beautifulsoup

PS。您已经在 /usr/local 中安装了一个版本的 feedparse。还有一个用于 feedparser 的 Ubuntu 软件包:python-feedparser. 它可能不是那么新,但安装它会为您引入所有依赖项。

于 2011-02-10T17:06:42.747 回答
0

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

如上所述,当您运行 Python 解释器并只需键入

import BeautifulSoup
print BeautifulSoup.__file__
dir(BeautifulSoup)
BeautifulSoup.BeautifulSoup
于 2011-02-23T23:18:24.813 回答
0

我将分享我是如何修复这个错误的:我在 Eclipse 上使用 Pydev 作为 IDE,而我犯的错误是在安装 Pydev 期间。我为解释器选择了自动配置。这导致包含 Python 2.7 作为解释器,从而导致错误。

于 2015-12-11T08:54:18.143 回答