例如:我想查找类为“author”(soup.findall(class_='author')
)的元素的内容,但跳过类为“comments”(soup.findall(class_='comments')
)的元素的内部搜索。你知道吗
所以类“author”,但不在任何带有类“comments”的元素中
有没有可能在bs里做这样的事?你知道吗
示例html:
<div class ='article'>
<span class='author'> John doe</span> <h3>title</h3>
(...)
<div class='comments'>
<div class='row'>
<span class='author'>Whining anon</span>
<div class='content'>
(...)
</div>
</div>
</div>
</div>
或“不区分大小写包含”版本:
我欢迎任何关于代码等方面的建议/清理。如果有人能想出如何使其可重用的方法,那就太好了,比如
findAll(class_="test", not_under="junk")
我认为一种方法是使用for循环和if语句来使用.parent进行过滤。这可以清理你的需要,但它的工作使用项。父项['class']获取包含的divs类以进行比较。你知道吗
或者作为一种理解:
相关问题 更多 >
编程相关推荐