python - 为什么在尝试导入 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 制作应用程序。
解决方案
你必须先导入bs4(假设你已经安装了bs4),即
> import bs4
> soup=bs4.BeautifulSoup(r.Text, "xml")
推荐阅读
- spring - spring-cloud-starter-sleuth + axon-tracing-spring-boot-starter =?
- python - 使用 pyodbc 从 Access 中删除行时遇到问题
- javascript - 输入字段在表单中不可编辑
- google-cloud-platform - 如何使用 Google Cloud Composer 设置 dbt?
- .net - .NET Core API - 将值 {null} 转换为类型“System.Boolean”时出错
- dynamics-crm - 动态 API - 在创建时关联多对多实体
- gurobi - Cvxpy:如何抑制/向后映射 cvxpy 的转换问题?
- docker - 使用 docker compose up -d 时等待特定容器
- sql - 查询以仅从单元格中获取数字 - 雪花
- azure-data-explorer - Azure 监视器规则的自定义条件不显示预期数据