beautifulsoup如何从特定类中提取文本

问题描述

我要从div中打印出具有此类class =“ enrte_text_itempo”的文本,是否可以仅通过键入此字符或类似内容来打印它?

for div in soup.find_all("div",{ class = "enrte_text_itempo"}):
    print(div.get_text())

因为我收到一条错误消息,指出语法无效,并指出了我的话:类

解决方法

使用正确的语法:

desired_divs = soup.find_all("div",{"class" : "enrte_text_itempo"})

OR

您可以通过class_关键字进行搜索:

desired_divs = soup.find_all("div",class_="enrte_text_itempo")
for div in desried_divs:
    print(div)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...