python - 在 Beautiful soup 中解析 html

标签 python beautifulsoup

我尝试像这样解析 html 片段:

<div><span>adrress</span>text of address</div>

如何在 Beautiful soup 中以编程方式获取片段“地址文本”而无需 span 标记?

现在我获取 div 的全部内容并删除 span,但我认为有更好的方法

最佳答案

>>> fragment = '<div><span>adrress</span>text of address</div>'
>>> soup = BeautifulSoup(fragment)
>>> soup.div.span.nextSibling
u'text of address'

关于python - 在 Beautiful soup 中解析 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17193152/

相关文章:

python - pygresql copy_from 给出关系不存在错误

python - 在自己的观察者回调中修改 tkinter 变量

python - 使用 Beautiful Soup 和 Python 抓取 Asp.NET 网站

python - 从字符串 python 中剪切中间单词

python - 如何用漂亮的汤跳过<span>

python - 序列化 `numpy.dtype` 对象 : human readable

python - 从无限滚动的网页获取所有文章链接?

python - 处理图像下载弹出窗口

python - 处理 BeautifulSoup 的错误链接的最佳方法是什么?

python - 按包含 str 过滤 Pandas 数据帧行