Python error: 'NoneType' object has no attribute 'find_all'

前端 未结 1 1451
渐次进展
渐次进展 2021-01-06 14:12

I\'m adapting a web scraping program from, http://danielfrg.com/blog/2013/04/01/nba-scraping-data/#disqus_thread, to scrape ESPN for baseball data into a CSV. However when I

相关标签:
1条回答
  • 2021-01-06 15:04

    The error means that the table variable that you are building by doing:

    table = BeautifulSoup(r.text).table
    

    is returning None. And for row in table.find_all("tr")[1:]: on a None is throwing the error.

    You can check if the url in question has a table in the way you are trying to access it. You can do this by printing out the url constructed by this statement:

    BASE_URL.format(row['prefix_1'], year, row['prefix_2'])
    

    and then going to this url in your browser to check if it has the table of your interest.

    0 讨论(0)
提交回复
热议问题