Skip to content

Instantly share code, notes, and snippets.

@sakamer71
Created April 15, 2022 19:57
Show Gist options
  • Save sakamer71/e39effb4a379e728a68241e078bf4aa8 to your computer and use it in GitHub Desktop.
Save sakamer71/e39effb4a379e728a68241e078bf4aa8 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
url = 'https://www.pro-football-reference.com'
year = 2021
r = requests.get(url + '/years/' + str(year) + '/fantasy.htm')
soup = BeautifulSoup(r.content, 'html.parser')
parsed_table = soup.find_all('table')[0]
#print(parsed_table)
for i,row in enumerate(parsed_table.find_all('tr')[2:]):
dat = row.find('td', attrs={'data-stat': 'player'})
if dat:
name = dat.a.get_text()
stub = dat.a.get('href')
else:
name=''
stub=''
print(name, stub)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment