I'm having issues with scraping pro-football-reference.com. I'm trying to access the "Team Offense" table but can't seem to target the div/table. The best I can do is:
soup.find('div', {'id':'all_team_stats})
which doesn't return the table nor it's immediate div wrapper. The following attempts return "None":
soup.find('div', {'id':'div_team_stats'})
soup.find('table', {'id':'team_stats'})
I've already scraped different pages simply by:
soup.find('table', {'id':'table_id})
but I can't figure out why it's not working on this page. Below is the code I've been working with. Any help is much appreciated!
from bs4 import BeautifulSoup
import urllib2
def make_soup(url):
page = urllib2.urlopen(url)
soupdata = BeautifulSoup(page, 'lxml')
return soupdata
def get_player_totals():
soup = make_soup("http://www.pro-football-reference.com/years/2015/")
tableStats = soup.find('table', {'id':'team_stats'})
return tableStats
print get_player_totals()
EDIT:
Thanks for all the help everyone. Both of the provided solutions below have been successful. Much appreciated!