Created
September 5, 2024 05:53
-
-
Save ricardodani/8e26d116ba79dced5da27b5e06a40201 to your computer and use it in GitHub Desktop.
salvar_tabela_brasileirao_excel.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Required libraries: | |
| - selenium | |
| - pandas | |
| - openpyxl | |
| """ | |
| from selenium import webdriver | |
| from selenium.webdriver.common.by import By | |
| from datetime import date | |
| import pandas | |
| def get_tabela_brasileirao(): | |
| URL_TABELA = 'https://ge.globo.com/futebol/brasileirao-serie-a/' | |
| navegador = webdriver.Chrome() | |
| navegador.get(URL_TABELA) | |
| equipes_nome = navegador.find_element( | |
| By.CLASS_NAME, "tabela__equipes" | |
| ).find_elements( | |
| By.CLASS_NAME, "classificacao__equipes--nome" | |
| ) | |
| equipes_pontos = navegador.find_element( | |
| By.CLASS_NAME, "tabela__pontos" | |
| ).find_elements( | |
| By.CLASS_NAME, "classificacao__tabela--linha" | |
| ) | |
| tabela_montada = [] | |
| for pos in range(len(equipes_nome)): | |
| p, j, v, e, d, gp, gc, sg, per = equipes_pontos[pos].text.split() | |
| tabela_montada.append( | |
| [ | |
| pos + 1, | |
| equipes_nome[pos].text, | |
| p, j, v, e, d, gp, gc, sg, per, | |
| ] | |
| ) | |
| navegador.close() | |
| return ( | |
| ["#", "Time", "P", "J", "V", "E", "D", "GP", "GC", "SG", "%"], | |
| tabela_montada | |
| ) | |
| def salvar_excel(): | |
| colunas, tabela = get_tabela_brasileirao() | |
| nome_arquivo_saida = f'brasileirao-{date.today()}.xlsx' | |
| data_frame = pandas.DataFrame(tabela, columns=colunas) | |
| data_frame.to_excel(nome_arquivo_saida, index=False) | |
| print(f"Salvo em {nome_arquivo_saida}") | |
| if __name__ == '__main__': | |
| salvar_excel() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment