-
Notifications
You must be signed in to change notification settings - Fork 1
/
Scrap.py
40 lines (32 loc) · 1.18 KB
/
Scrap.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
from datetime import date, timedelta
from bs4 import BeautifulSoup
from lib.imports import *
from pathlib import Path
import requests
import json
import csv
def main():
print("[!] Starting `Scrap.py`")
''' Comments for working over a local file '''
# print("[!] Getting the http request")
# with open("raw_test.html", "r") as f: html = f.read()
# soup = BeautifulSoup(raw_html, 'html.parser')
print("[!] Getting the http request")
raw_html = requests.get("https://www.worldometers.info/coronavirus/#countries").text
print("[!] Souping the responce")
soup = BeautifulSoup(raw_html, 'html.parser')
print("[!] Getting the table")
titles, data = getTableList(soup_object=soup)
print("[!] Getting todays date")
file_name = getTodaysDateFileName()
print("[!] Saving the files into .json formate")
setJsonFile(file_name, data)
print("[!] Saving the files into .csv formate")
setCsvFile(file_name, titles, data)
print("[!] Completed")
def getTodaysDateFileName():
d = 'data' + date.today().strftime('-%d-%m-%Y')
return d
if __name__ == "__main__":
main()
# Link-Used: https://www.worldometers.info/coronavirus/#countries