让 BeautifulSoup 以不区分大小写的方式捕获标签
我想用 BeautifulSoup 捕获一些标签:一些
标签、
我注意到 BeautifulSoup 默认区分大小写。如何以不区分大小写的方式捕获这些标签?
I want to catch some tags with BeautifulSoup: Some <p>
tags, the <title>
tag, some <meta>
tags. But I want to catch them regardless of their case; I know that some sites do meta like this: <META>
and I want to be able to catch that.
I noticed that BeautifulSoup is case-sensitive by default. How do I catch these tags in a non-case-sensitive way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
BeautifulSoup 标准化了输入的解析树。它将标签转换为小写。 IMO 你不用担心。
BeautifulSoup standardises the parse tree on input. It converts tags to lower-case. You don't have anything to worry about IMO.
您可以使用 soup.findAll 应该不区分大小写匹配:
结果:
You can use soup.findAll which should match case-insensitively:
Result: