没有class属性美丽的汤提取元素 [英] beautiful soup extract element with no class attribute

查看:135
本文介绍了没有class属性美丽的汤提取元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要导航到特定类型的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 class types. I need one which does NOT have any class attribute. SHould I look for one with class = '' or is there some other way?

推荐答案

使用

soup.findAll(attrs={'class': None})

从文档报价:

如果你需要把进口的属性,其名称是Python的保留字,像类的限制,或者您可以使用ATTRS;或属性,其名称都是非关键字参数来美丽的汤搜索方式:名称,递归限制,文本或ATTRS本身。

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆