简体   繁体   English

beautifulsoup 如何从特定的 class 中提取文本

[英]beautifulsoup how to extract text from a specific class

I want to print a text from div that has this class="enrte_text_itempo" Can i print it just by typing this or someithng like this?我想从具有此类的 div 中打印文本 =“enrte_text_itempo” 我可以通过键入这个或类似的东西来打印它吗?

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

because i get an error that says invalid syntax and points my word:class因为我收到一个错误,指出语法无效并指出我的话:class

Using the correct syntax:使用正确的语法:

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

OR或者

You could search by the class_ keyword:您可以通过class_关键字搜索:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM