提取没有类属性的元素 [英] 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.
这篇关于提取没有类属性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文