Skip to main content
 首页 » 编程设计

python之使用 BeautifulSoup Python 3 时遇到问题

2024年10月25日9luoye11

无论我使用 bs4、beautifulsoup4 还是 BeautifulSoup,我都会不断得到回溯

Traceback (most recent call last): 
  File "<pyshell#3>", line 1, in <module> 
    from BeautifulSoup import BeautifulSoup 
ImportError: No module named 'BeautifulSoup' 

在终端我得到

Peters-Mac-mini:~ admin$ pip install beautifulsoup4 
Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-packages 
Cleaning up... 

这是我第一次尝试使用 BeautifulSoup,但我从未在其他安装中遇到过此错误。不知道如何摆脱它!我在 Stack Overflow 帖子中没有看到这个问题。

请您参考如下方法:

您需要从 bs4 导入,而不是 BeautifulSoup。

from bs4 import BeautifulSoup