Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python BeautifulSoup4中的访问值_Python_Python 3.x_Beautifulsoup - Fatal编程技术网

Python BeautifulSoup4中的访问值

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

我提出了一个HTML请求,希望从中检索特定元素,但我不知道如何使用BeautifulSoup4访问它们

以下是返回的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                    &nbsp;
</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                    &nbsp;
        </td>
       '''
soup = BeautifulSoup(html, 'html.parser')
obj = soup.find('span', text='Identifiers:').nextSibling
print(obj)

可能复制的作品像一个魅力!谢谢:)
 AF118324[sampleid]