ipl_href

mail@pastecode.io avatar
unknown
python
2 years ago
2.0 kB
2
Indexable
Never
ipl_map = {
    "CSK": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/chennai-super-kings-squad-1300871/series-squads",
    "DC": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/delhi-capitals-squad-1300872/series-squads",
    "GT": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/gujarat-titans-squads-1300880/series-squads",
    "KKR": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/kolkata-knight-riders-1300869/series-squads",
    "LSG": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/lucknow-super-giants-squad-1300877/series-squads",
    "MI": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/mumbai-indians-squad-1300874/series-squads",
    "PBKS": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/punjab-kings-squad-1300870/series-squads",
    "RR": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/rajasthan-royals-squad-1300873/series-squads",
    "RCB": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/royal-challengers-bangalore-squad-1300868/series-squads",
    "SRH": "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/sunrisers-hyderabad-squad-1300875/series-squads"
}

arr = []
# ipl_url = "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/delhi-capitals-squad-1300872/series-squads"
# ipl_url = "https://www.espncricinfo.com/series/indian-premier-league-2022-1298423/chennai-super-kings-squad-1300871/series-squads"
for team, ipl_url in ipl_map.items():
    i = 0
    print(team)
    ipl_page = requests.get(ipl_url)
    iplbs = BeautifulSoup(ipl_page.text, 'html.parser')
    
    for child in iplbs.find("div", {"class": "container-fluid"}).find("div", {"class": "row"}):
        arr2 = []
        arr2.append(child.find("a", href=True)["href"].split('-')[-1])
        arr2.append(team)
        i += 1
        arr.append(arr2)

    print(i)