vendredi 9 novembre 2018

Python Webscraping - BeautifulSoup Attribute Error

Trying to learn about webscraping and currently working on scraping the team stats data off the nfl website for a specific team(chiefs).

import requests
from bs4 import BeautifulSoup 

data = requests.get('http://www.nfl.com/teams/kansascitychiefs/statistics? 
team=KC')

#parser
soup = BeautifulSoup(data.text, 'html.parser')

main = soup.find('div',{'id':'team-stats-wrapper'})
teamstats = soup.find('table',{'id':'data-table1'})
for tbody in teamstats.find('tbody'):
    print(tbody)

the main and teamstats variables are just specifying what part of the html code I want to use from the website as you all know.

I'm getting the attribute error in the for statement, saying "File "", line 1, in AttributeError: 'NoneType' object has no attribute 'find_all'

Thanks for your help!




Aucun commentaire:

Enregistrer un commentaire