-
Notifications
You must be signed in to change notification settings - Fork 0
/
points_table.py
52 lines (46 loc) · 1.8 KB
/
points_table.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
import asyncio
from pyppeteer import launch
from bs4 import BeautifulSoup
import pandas as pd
async def main():
browser = await launch()
page = await browser.newPage()
await page.goto('https://www.iplt20.com/points-table/men/2024')
await page.waitFor(3000)
html = await page.content()
await browser.close()
print("SCRAPPED ALL DATA")
return html
html_response = asyncio.get_event_loop().run_until_complete(main())
soup = BeautifulSoup(html_response, "html.parser")
points_table = soup.find('tbody', {"id": "pointsdata"})
rows = points_table.findChildren("tr", recursive=False)
data = []
teams = {"ROYAL CHALLENGERS BENGALURU": "RCB", "GUJARAT TITANS": "GT", "DELHI CAPITALS": "DC", "PUNJAB KINGS": "PBKS", "RAJASTHAN ROYALS": "RR",
"SUNRISERS HYDERABAD": "SRH", "LUCKNOW SUPER GIANTS": "LSG", "CHENNAI SUPER KINGS": "CSK", "KOLKATA KNIGHT RIDERS": "KKR", "MUMBAI INDIANS": "MI", "ROYAL CHALLENGERS BANGALORE":"RCB"}
table = []
for i in rows:
qualified = i.find('span', {"class":"standings_qualified ng-scope"})
data = []
row_data = i.text.split(" ")
record = [x for x in row_data if x != ""]
# [POS TEAM P W L NR NRR PTS]
data.append(record[1])
data.append(record[2])
data.append(record[3])
data.append(record[4])
data.append(record[5])
data.append(record[6])
data.append(record[7])
data.append(record[8])
data.append(record[9])
if qualified != None:
data.append("Yes")
else:
data.append("No")
print(data)
table.append(data)
df = pd.DataFrame(table, columns=['TEAM', 'P', 'W', 'L', 'NR', "NRR","FOR","AGAINST", "PTS","QUALIFIED"])
df.to_csv('data\points.csv', index=False)
# df = pd.DataFrame(data, columns=['match', 'venue', 'date', 'time', 'team1','team2',"year"])
# df.to_csv('points_table.csv', index=False)