2024-09-27 07:31:12 发布
网友
当我们要查找的属性值已知时,就是这样做的:
from bs4 import BeautifulStoneSoup soup = BeautifulStoneSoup(html, 'html.parser') found_elems = soup.find_all(attrs={"myattribute" : "myknownvalue"})
在不知道其值的情况下,如何查找具有“myattribute”属性的所有元素
另一种方法是使用CSS选择器:
found_elems = soup.select('[myattribute]')
更多关于CSS选择器here
如果您不知道属性的值,请将其设置为True:
True
from bs4 import BeautifulStoneSoup soup = BeautifulStoneSoup(html, 'html.parser') found_elems = soup.find_all(attrs={"myattribute": True})
另一种方法是使用CSS选择器:
更多关于CSS选择器here
如果您不知道属性的值,请将其设置为
True
:相关问题 更多 >
编程相关推荐