I make a discord bot and one funtion is that you can get stats for champions from the game League of Legends, now i have 3 code parts that are actually the same, there are just 2 things that are different. Is it possible to make a for loop or something like that to put them in on function?
#winrate
elem = soup.find_all("tr", {"id": "statistics-win-rate-row"})
table = str(elem[0])
tablerow = table.splitlines()
for item in tablerow:
if "%" in item:
item = item.replace(" ", "")
winrate = item
break
#playrate
elem = soup.find_all("tr", {"id": "statistics-play-rate-row"})
table = str(elem[0])
tablerow = table.splitlines()
for item in tablerow:
if "%" in item:
item = item.replace(" ", "")
playrate = item
break
#banrate
elem = soup.find_all("tr", {"id": "statistics-ban-rate-row-row"})
table = str(elem[0])
tablerow = table.splitlines()
for item in tablerow:
if "%" in item:
item = item.replace(" ", "")
banrate = item
break