2024-05-29 00:22:09 发布
网友
我有一系列由find\u all()返回的列表项
<li class="rsltItem" mh-property-list-item="".......
该项有许多嵌套元素。在
有时,其中一个li稍有不同:
这个有较少的不同的嵌套元素。我要消除第二种类型。在
我尝试过在特定的类中搜索li,但是即使它们不同,它也会返回所有的值:
有什么办法可以从我的结果中排除第二个列表项吗?在
result_list = [tag for tag in soup.find_all('li', {'class': 'rsltItem'}) if tag['class'] == ['rsltItem']]
或者
要只查找与特定类rsltItem匹配的标记<li>
rsltItem
<li>
soup.find_all(lambda tag: tag.name == 'li' and tag.get('class') == ['rsltItem'])
或者
^{pr2}$要只查找与特定类
rsltItem
匹配的标记<li>
相关问题 更多 >
编程相关推荐