我正在尝试从提到的URL中提取数据(59,805)。我正在使用BeautifulSoup和Python的请求包。
下面是我正在尝试的代码,但是没有任何结果。下面是HTML代码,我尝试从中提取。结果应为“已确认”,59,805
import requests
from bs4 import BeautifulSoup as bs
import pandas as pd
case_type = []
count = []
url = requests.get('https://www.covid19india.org/')
soup = bs(url.content,'html.parser')
for a in soup.findAll('div', attrs={'class':'level-item is-cherry fadeInUp'}):
b = a.find('h1')
c = a.find('h5')
case_type.append(c.text)
count.append(b.text)
df = pd.DataFrame({'Case Type':case_type, 'Count':count})
print(df)
所述网页的HTML代码段
<div class="Level">
<div class="level-item is-cherry fadeInUp" style="animation-delay: 1s;">
<h5>Confirmed</h5>
<h4>[+115]</h4>
<h1>59,805 </h1>
</div>
<div class="level-item is-blue fadeInUp" style="animation-delay: 1.1s;">
<h5 class="heading">Active</h5>
<h4> </h4>
<h1 class="title has-text-info">39,914</h1>
</div>
<div class="level-item is-green fadeInUp" style="animation-delay: 1.2s;">
<h5 class="heading">Recovered</h5>
<h4>[+14]</h4>
<h1 class="title has-text-success">17,901 </h1>
</div>