提取没有 class 属性的元素 [英] Extract element with no class attribute
问题描述
我需要导航到特定类型的 html 元素.然而,页面上有很多这种类型的元素,有很多不同的类.
I need to navigate to an html element of a particular type. However, there are many such elements of that type on the page, with many different classes.
我需要一个没有任何类属性.
我应该用 class == ''
寻找一个,还是有其他方法?
Should I look for one with class == ''
, or is there some other way?
推荐答案
使用
soup.findAll(attrs={'class': None})
引自文档:
如果需要对名称为 Python 保留字的属性(如 class、for 或 import)进行限制,则可以使用 attrs;或名称为 Beautiful Soup 搜索方法的非关键字参数的属性:名称、递归、限制、文本或属性本身.
You can use attrs if you need to put restrictions on attributes whose names are Python reserved words, like class, for, or import; or attributes whose names are non-keyword arguments to the Beautiful Soup search methods: name, recursive, limit, text, or attrs itself.
这篇关于提取没有 class 属性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!