问题描述
我要从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)