Python 提取特定a标记后面的文本
我用python从html代码中提取文本时遇到问题。代码如下所示:Python 提取特定a标记后面的文本,python,html,string,beautifulsoup,extract,Python,Html,String,Beautifulsoup,Extract,我用python从html代码中提取文本时遇到问题。代码如下所示: <div class="..."> <br/><a href="link1.html" title="title1">anchor1</a>text1 <br/><a href="link2.html" title="title2">anchor2</a>important text to extract <br/><a hre
<div class="...">
<br/><a href="link1.html" title="title1">anchor1</a>text1
<br/><a href="link2.html" title="title2">anchor2</a>important text to extract
<br/><a href="link3.html" title="title3">anchor3</a>text3
...
</div>
text1
要提取的重要文本
text3
...
我只想提取一个特定链接后面的文本。我知道主持人的一些话。因此,提取a标签和beautiful soup 4之间的内容不是问题。但是在搜索了相当多的时间后,我没有找到解决方案,只能提取我重要的a标签后面的文本
我希望有人有想法。例如,通过标题找到链接,并获得:
from bs4 import BeautifulSoup
data = """
<div class="...">
<br/><a href="link1.html" title="title1">anchor1</a>text1
<br/><a href="link2.html" title="title2">anchor2</a>important text to extract
<br/><a href="link3.html" title="title3">anchor3</a>text3
...
</div>
"""
soup = BeautifulSoup(data)
print soup.find('a', title='title2').next_sibling
important text to extract