美丽的汤:提取H2标记之间的数据

2024-10-06 11:24:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个html文本如下

<h2 class="ArticleBody-styles-makeit-subtitle--LnHeO">1. Python</h2>

通过使用Beautiful Soup,我们如何提取1. Python文本

我正在努力

data = [ <h2 class="ArticleBody-styles-makeit-subtitle--LnHeO">1. Python</h2> , 
<h2 class="ArticleBody-styles-makeit-subtitle--LnHeO">2. HTML</h2> ]
for item in data :
  text = item.findAll('h2')
  print(text.get_text())

非常感谢您的建议


Tags: text文本datahtmlh2itemclasssoup