-
Notifications
You must be signed in to change notification settings - Fork 1
/
scrap.py
71 lines (49 loc) · 1.36 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 21 15:52:20 2020
@author: HP-intel
"""
import requests
import re
import time
from bs4 import BeautifulSoup
def cv():
url="https://www.worldometers.info/coronavirus/country/india/"
page = requests.get(url)
page=page.text
soup = BeautifulSoup(page, "html.parser" )
l1=[]
b = soup.findAll("h1")
for i in b:
y=i.text
res1 = "".join(re.split("[^a-zA-Z]*", y))
l1.append(res1)
d={}
c =soup.findAll("div", {"class":"maincounter-number"})
j=1
for i in c:
x=i.text
res = str(re.sub("\D", "", x))
d[l1[j]]=res
j+=1
print("\n\n",l1[0]," Stats")
for x, y in d.items():
print(x,":", y)
url2="https://www.worldometers.info/coronavirus/"
page2 = requests.get(url2)
page2=page2.text
soup2 = BeautifulSoup(page2, "html.parser" )
c2 =soup2.findAll("div", {"class":"maincounter-number"})
d={}
j=1
for i in c2:
x=i.text
res = str(re.sub("\D", "", x))
d[l1[j]]=res
j+=1
print("\n\nWorld Stats")
for x, y in d.items():
print(x,":", y)
for i in range(0,3,1):
cv()
time.sleep(120)