BeautifulSoup问题 [英] BeautifulSoup question

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

问题描述

<parent1>
    <span>Text1</span>
</parnet1>
<parent2>
    <span>Text2</span>
</parnet2>
<parent3>
    <span>Text3</span>
</parnet3>

我与Python和放大器解析这一点; BeautifulSoup。我有一个变量的 soupData 存储的需求对象的指针。我怎样才能获得指针在 parent2 ,例如,如果我有文字的文本2 。所以,问题是内容过滤跨度标签。我怎样才能做到这一点?

I'm parsing this with Python & BeautifulSoup. I have a variable soupData which stores pointer for need object. How can I get pointer for the parent2, for example, if I have the text Text2. So the problem is to filter span-tags by content. How can I do this?

推荐答案

修正的结束标记拼写后:

After correcting the spelling on the end-tags:

[e for e in soup(recursive=False, text=False) if e.span.string == 'Text2']

这篇关于BeautifulSoup问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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