Python BeautifulSoup4中的访问值
我提出了一个HTML请求,希望从中检索特定元素,但我不知道如何使用BeautifulSoup4访问它们 以下是返回的html的示例:Python BeautifulSoup4中的访问值,python,python-3.x,beautifulsoup,Python,Python 3.x,Beautifulsoup,我提出了一个HTML请求,希望从中检索特定元素,但我不知道如何使用BeautifulSoup4访问它们 以下是返回的html的示例: <td valign="top" > <span class="recordAttribute" >Taxonomy</span>: Mollusca, Gastropoda, Littorinimorpha, Hydrobiidae, Hydrobia<br> <span class="rec
<td valign="top" >
<span class="recordAttribute" >Taxonomy</span>: Mollusca, Gastropoda, Littorinimorpha, Hydrobiidae, Hydrobia<br>
<span class="recordAttribute" >Identifiers:</span> AF118324[sampleid] <br>
<span class="recordAttribute" >Depository</span>: Mined from GenBank, NCBI
</td>
分类学:软体动物、腹足类、滨线动物、水螅科、水螅目
标识符:AF118324[sampleid]
存管:从NCBI的GenBank开采
我想访问元素AF118324(它是标识符span类后面的名称)
我怎样才能访问它?(当然不使用子字符串方法)这对您有用吗
html = '''
<td valign="top" >
<span class="recordAttribute" >Taxonomy</span>: Mollusca, Gastropoda, Littorinimorpha, Hydrobiidae, Hydrobia<br>
<span class="recordAttribute" >Identifiers:</span> AF118324[sampleid] <br>
<span class="recordAttribute" >Depository</span>: Mined from GenBank, NCBI
</td>
'''
soup = BeautifulSoup(html, 'html.parser')
obj = soup.find('span', text='Identifiers:').nextSibling
print(obj)
可能复制的作品像一个魅力!谢谢:)
AF118324[sampleid]