BeautifulSoup <span> foo </span>结果

时间:2016-08-06 03:34:18

标签: python html beautifulsoup

HTML代码:

<div id="descProdotto"> <img alt="Mont Blanc Eyewear" class="logoDesc" src="http://151.9.39.27/nfs/Immagini/Loghi_Linee/BA.png"/> <p><span>Nome:</span> BA0055</p> <p><span>Occh.:</span> Metallo</p> <p><span>Forma:</span> Geometrico</p> <p><span>Tipo:</span> Cerchiato</p> <p><span>Asta Flex:</span> No</p> <p><span>Fitting:</span> Caucasian</p> <img class="separatore" height="11" src="../../Grafica/Icone/separator_S.png" width="197"/>
<div class="glassDes">
<p class="scroll"></p>
</div>

Python代码:

from bs4 import BeautifulSoup

def get_description(sorgente):
    soup = BeautifulSoup(sorgente, 'html.parser')
    list = soup.find_all("p")
    for a in list:
        print(a.find('Nome:')

code = driver.page_source

get_description(code)

我无法在变量中提取值:NomeBA0055

我该怎么做?

谢谢

1 个答案:

答案 0 :(得分:0)

按文字查找span元素并获取next sibling

soup.find("span", text="Nome:").next_sibling