【问题标题】:Using BeautifulSoup Library with Python在 Python 中使用 BeautifulSoup 库
【发布时间】:2012-10-21 17:16:18
【问题描述】:

我正在学习使用 Python 和 Beautiful Soup 库创建地图的教程。

我已经下载了beautifulsoup4-4.1.3,文件夹名为“beautifulsoup4-4.1.3”。此文件夹的内容在附件中。

在教程中,我得到了以下代码,用于导入我的数据和漂亮的汤:

import csv
from BeautifulSoup import BeautifulSoup

问题是美汤文件夹中没有名为“美汤”的文件。我还附上了我在终端中收到的错误消息。

如果没有该名称的文件,我应该如何导入美丽的汤?我尝试简单地将文件夹名称更改为“美丽的汤”。我没想到它会起作用,我是对的 - 它没有。

欢迎对如何进行的任何建议?

【问题讨论】:

  • 打开终端,启动 python 并输入:help('modules')。你在那里看到任何与BeautifulSoup 相关的东西吗?

标签: python beautifulsoup


【解决方案1】:

您安装了 BeautifulSoup 库版本 4,该库已重命名:

from bs4 import BeautifulSoup

如果您想要旧名称和匹配的 API,则需要安装 BeautifulSoup 3:

easy_install BeautifulSoup

请注意,由于您的教程使用的是 from BeautifulSoup import BeautifulSoup,因此它可能无法完全与 BeautifulSoup 版本 4 的更新 API 一起使用。如果遇到问题,请查看 BeautifulSoup 文档的 porting to BS4 部分以“翻译” BS 3 代码到 4 API。

【讨论】:

    【解决方案2】:

    要么将bs4 文件夹移动到与脚本相同的目录中,要么通过easy_installpip 安装模块。然后你可以像这样导入它:

    from bs4 import BeautifulSoup
    

    【讨论】:

      【解决方案3】:

      要使用 BeautifulSoup 4,您需要:

      from bs4 import BeautifulSoup
      

      在我看来你读错了手册。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-18
        • 2014-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多