-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathscript.py
52 lines (39 loc) · 1.37 KB
/
script.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
46
47
48
49
50
51
#import the Beautiful soup functions to parse the data returned from the website
from bs4 import BeautifulSoup
# Import pandas to make data tables and to import it to CSV
import pandas as pd
#import the library used to query a website
import urllib.request
class AppURLopener(urllib.request.FancyURLopener):
version = "Mozilla/5.0"
x = 1
while x == 1:
#specify the url
website = "https://www.google.com/covid19-map/"
#Query the website and return the html to the variable 'page'
page = AppURLopener().open(website)
#Parse the html in the 'page' variable, and store it in Beautiful Soup format
soup = BeautifulSoup(page, 'html.parser')
# print(soup.title)
all_tables = soup.find_all('table', class_='SAGQRd')
right_table = all_tables[0]
rows = right_table.findAll("tr")
datas = rows[1].findAll("td")
#print('Confirmed Cases : ' + datas[1].string)
#print('Recovered : ' + datas[3].string)
#print('Deaths : ' + datas[4].string)
# make a table from the data
stat = pd.DataFrame(
{
'Confirmed Cases': [datas[1].string],
'Recovered': [datas[3].string],
'Deaths': [datas[4].string],
}
)
print(stat)
html = (stat.to_html())
# Export the table to csv
stat.to_csv('stats.csv')
# Export the table to HTML
stat.to_html('stats.html')
print(html)