arc*_*123 6 python beautifulsoup python-3.x
我正在喝美味的汤.我有一个HTML字符串:
<div><b>ignore this</b>get this</div>
Run Code Online (Sandbox Code Playgroud)
如何检索"得到这个",而忽略" 忽略这个 "
谢谢
dre*_*cat 13
您可以获取div文本而不是递归检索子文本:
>>> from bs4 import BeautifulSoup
>>> soup = BeautifulSoup('<div><b>ignore this</b>get this</div>')
>>> soup.div.find(text=True, recursive=False)
u'get this'
Run Code Online (Sandbox Code Playgroud)
这与儿童的文本位置无关:
>>> soup = BeautifulSoup('<div>get this<b>ignore this</b></div>')
>>> soup.div.find(text=True, recursive=False)
u'get this'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5368 次 |
| 最近记录: |