You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python中'module' object is not callable错误求助,需解析网页数据

解决'module' object is not callable错误并成功解析网页数据

错误根源是你导入BeautifulSoup的方式不对。你用import bs4 as BeautifulSoup把整个bs4模块重命名成了BeautifulSoup,之后尝试直接调用这个模块——但模块本身不能像函数/类那样被调用,你需要的是调用bs4模块里的BeautifulSoup类。

修正后的代码:

!pip install bs4
!pip install html5lib
import pandas as pd
!pip install lxml
import requests
from bs4 import BeautifulSoup  # 直接导入模块中的BeautifulSoup类

url = "https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-PY0220EN-SkillsNetwork/labs/project/netflix_data_webpage.html"

data=requests.get(url).text

soup = BeautifulSoup(data,'html5lib')  # 现在调用的是可实例化的类,不会报错

如果习惯用模块别名的写法,也可以改成这样:

import bs4 as bs  # 给模块起别名
# ... 其他代码不变

soup = bs.BeautifulSoup(data,'html5lib')  # 通过模块别名访问类

内容的提问来源于stack exchange,提问作者Inam Buneri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 22:30:05