首页 > 解决方案 > 为什么在尝试导入 BeautifulSoup 时出现“NameError: name 'bs4' is not defined”错误?

问题描述

> soup=bs4.BeautifulSoup(r.Text, "xml")

回溯(最近一次通话最后):

File "<ipython-input-14-ad3307f493a7>", line 1, in <module>
    soup=bs4.BeautifulSoup(r.Text, "xml")

**NameError: name 'bs4' is not defined**

我该如何解决这个问题?我正在尝试使用 BeautifulSoup 制作应用程序。

标签: pythonspyder

解决方案


你必须先导入bs4(假设你已经安装了bs4),即

> import bs4
> soup=bs4.BeautifulSoup(r.Text, "xml")

推荐阅读