Skip to content

Instantly share code, notes, and snippets.

@paduel
Last active December 5, 2022 04:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paduel/0aa85f761e8f3a3f9504b5cc11cd5197 to your computer and use it in GitHub Desktop.
Save paduel/0aa85f761e8f3a3f9504b5cc11cd5197 to your computer and use it in GitHub Desktop.
FlashScore Live Events Parser
from requests_html import AsyncHTMLSession
import pandas as pd
from unicodedata import normalize
url = 'https://www.flashscore.com/'
asession = AsyncHTMLSession()
async def get_scores():
r = await asession.get(url)
await r.html.arender()
return r
# Renderiza el html de la web
results = asession.run(get_scores)
results = results[0]
events_dict = []
# Captura todos los eventos en live
events = results.html.find("div.event__match--live")
# Parsea cada evento
for event in events:
record = {}
record['id'] = event.attrs['id']
record['time'] = event.find("div.event__stage--block")[0].text
record['home_team'] = event.find("div.event__participant.event__participant--home")[0].text
record['score'] = normalize('NFKD', event.find("div.event__scores.fontBold")[0].text)
record['away_team'] = event.find("div.event__participant.event__participant--away")[0].text
record['event_part'] = normalize('NFKD', event.find("div.event__part")[0].text)[1:-1]
record['url_oods_uo'] = f"https://www.flashscore.com/match/{record['id'].split('_')[-1]}/#odds-comparison;over-under;full-time"
events_dict.append(record)
# Pasamos a DataFrame
df = pd.DataFrame(events_dict)
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment