Last active
November 8, 2020 08:53
-
-
Save otavio-s-s/eb7dd402f4f482b97c2d3466540510e6 to your computer and use it in GitHub Desktop.
This file contains 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
import pandas as pd | |
import numpy as np | |
import requests | |
from bs4 import BeautifulSoup | |
from time import sleep | |
def get_table(round, url=url): | |
round_url = f'{url}/{round}' | |
page = requests.get(round_url) | |
soup = BeautifulSoup(page.text, 'html.parser') | |
rows = [] | |
for child in soup.find_all('table')[4].children: | |
row = [] | |
for td in child: | |
try: | |
row.append(td.text.replace('\n', '')) | |
except: | |
continue | |
if len(row) > 0: | |
rows.append(row) | |
df = pd.DataFrame(rows[1:], columns=rows[0]) | |
return df | |
for round in range(1, 39): | |
table = get_table(round) | |
table.to_csv(f'PL_table_matchweek_{round}.csv', index=False) | |
sleep(np.random.randint(1, 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment