如何使用python从以下源中提取数据?

时间:2019-07-17 08:34:50

标签: python selenium

我想从以下源代码中提取“ 63”

<center><br><strong>Total 63 Customer Accounts found </strong><br>

运行代码后,它应该打印63

1 个答案:

答案 0 :(得分:1)

尝试一下:

from bs4 import BeautifulSoup  
soup_html ='<center><br><strong>Total 63 Customer Accounts found in DSLAM: 10.131.0.133</strong><br>'   
soup = BeautifulSoup(soup_html , "html.parser")
str_res = soup.findAll(text=True)
result = [int(i) for i in str_res [0].split() if i.isdigit()]
print(result)

将返回63。