我想使用beautifulsoup
. 我想在不删除内部 html 标签的情况下提取标签内的文本。例如样本输入:
<a class="fl" href="https://stackoverflow.com/questio...">
Angular2 <b>Router link not working</b>
</a>
样本输出:
'Angular2 <b>Router link not working</b>'
我试过这个:
from bs4 import Beautifulsoup
string = '<a class="fl" href="https://stackoverflow.com/questio...">
Angular2 <b>Router link not working</b>
</a>'
soup = Beautifulsoup(string, 'html.parser')
print(soup.text)
但它给出了:
'Angular2 Router link not working'
如何在不删除内部标签的情况下提取文本?