从行获取工具提示

时间:2017-10-13 10:21:42

标签: python beautifulsoup

我正在尝试从表行获取工具提示但它返回None。 请查看我为此尝试的代码。

<tr onmouseover="this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='DodgerBlue';this.originalcolor=this.style.color;this.style.color='White';Tip('<span Style=Color:Red>License: <BR />20-214767 (Validity: 21/05/2022)<BR />20C-214769 (Validity: 21/05/2022)<BR />21-214768 (Validity: 21/05/2022)</span>');" onmouseout="this.style.backgroundColor=this.originalstyle;this.style.color=this.originalcolor;UnTip();" style="background-color:White;font-family:Times New Roman;font-size:12px;">
        <td style="font-size:10px;font-weight:normal;font-style:normal;text-decoration:none;" align="left">AAYUSH PHARMA</td><td style="font-size:10px;font-weight:normal;font-style:normal;text-decoration:none;" align="left">PUNE-1ST FLOOR, SR.NO.742/A, DINSHOW APARTMENT,,SWAYAM HOSPITAL AND NURSING HOME, BHAWANI PETH</td><td style="font-weight:normal;font-style:normal;text-decoration:none;" align="center">RH - 3</td><td>swapnil ramakant pawar, BPH, [140514-21/04/2017]</td>
</tr> 
  

想要获取以下工具提示的文字。

提示(&#39;许可证:
20-214767(有效期:21/05/2022)
20C-214769(有效期:21/05/2022)
21-214768(有效期:21/05/2022)&#39;

代码:

for row in soup.findAll("tr")[1:]:
    licence = row.find("span",{"Style":"Color:Red"})
    print(licence)

1 个答案:

答案 0 :(得分:1)

最后我得到了必需的输出

for row in soup.findAll("tr")[1:]:
    attr = row.get('onmouseover')
    Attrsoup = BeautifulSoup(attr,   'html.parser')
    print(Attrsoup.span.text)