使用 BeautifulSoup 查找特定标签 [英] Find a specific tag with BeautifulSoup

查看:45
本文介绍了使用 BeautifulSoup 查找特定标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 BS 轻松遍历通用标签,但我不知道如何找到特定标签.例如,如何找到 <div style="width=300px;"> 的所有出现?这对 BS 来说可能吗?

I can traverse generic tags easily with BS, but I don't know how to find specific tags. For example, how can I find all occurances of <div style="width=300px;">? Is this possible with BS?

推荐答案

以下应该有效

soup = BeautifulSoup(htmlstring)
soup.findAll('div', style="width=300px;")

有几种方法可以搜索标签.

There are couple of ways to search for tags.

了解和使用更多文字

这篇关于使用 BeautifulSoup 查找特定标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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