【发布时间】:2022-01-04 11:50:17
【问题描述】:
我正在使用 find_all() 获取特定标签 (td) 的所有准确度,但我想处理不同的类。 我的标签看起来像这样:
<td class="classname" colspan="2">
Something ...
</td>
我想根据类名做不同的事情。
我尝试使用 has_attr() 但它似乎只检查是否存在单个属性并且不适用于整个表达式。
for tag in soup.find_all("td"):
if tag.has_attr("td", {"class": "search-detail-heading"}):
Do Something()
if tag.has_attr("td", {"class": "search-detail-subject"}):
Do Something else()
还有其他方法可以检查这个类名吗?我需要调整 find_all() 吗?我有点不想将 find_all() 用于一个类类型,然后再用于下一个类类型。
【问题讨论】:
标签: python html web-scraping beautifulsoup