-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworldmeter.py
45 lines (34 loc) · 1.38 KB
/
worldmeter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from bs4 import BeautifulSoup
import requests
def coronaParsing():
url = 'https://www.worldometers.info/coronavirus/'
response = requests.get(url)
data = response.text
soup = BeautifulSoup(data, 'html.parser')
url_corona = soup.find_all('div', {'class': 'maincounter-number'})
###
title = [] # title[0], title[1], title[2] -> world confirmed case
# world confirmed Case
# for text in range(len(url_corona)):
# title.append(url_corona[text].find('span').text)
# vietnam corona case
viet = []
chart = soup.find('table', attrs={'id': "main_table_countries_today"})
chart_body = chart.find('tbody')
rows = chart_body.find_all('tr')
for row in rows:
cols = row.find_all('td')
cols = [ele.text for ele in cols]
viet.append([ele for ele in cols if ele])
for vietnam in viet:
if vietnam[0] == 'Vietnam':
title.append(vietnam[vietnam.index('Vietnam') + 1]) # 전체 감염자 수
if vietnam[vietnam.index('Vietnam') + 2] == ' ':
title.append('0')
else:
title.append(vietnam[vietnam.index('Vietnam') + 2]) # 사망자 수
title.append(vietnam[vietnam.index('Vietnam') + 3]) # 회복자 수
title.append(vietnam[vietnam.index('Vietnam') + 4]) # 신규 감염자수
return title
a = coronaParsing()
print(a)