Python BeautifulSoup - Attributerror:' Nonetype'对象没有属性' findAll'

时间:2017-10-04 18:23:29

标签: python beautifulsoup

运行此代码时出现回溯错误(见下文)。我对此很陌生,不能简单地理解为什么它不起作用

表tableStats.findAll中的行(' tr')[2:]: Attributerror:' Nonetype'对象没有属性' findAll'

    from bs4 import BeautifulSoup
    import urllib.request

    f = open('C:\Program Files (x86)\Python36-32\Projects\FFootball_DiamonMine\outfileESPN.txt','w')
    errorFile = open ('C:\Program Files (x86)\Python36-32\Projects\FFootball_DiamonMine\errorESPN.txt','w')

    x = 0
    while (x < 500):
        soup = BeautifulSoup(urllib.request.urlopen('http://games.espn.com/ffl/tools/projections?startIndex='+str(x)).read(), 'html.parser')
        tableStats = soup.find("table", ("class" "playerTableTable tableBody"))
        for row in tableStats.findAll('tr')[2:]:
            col = row.findAll('td')

            try:
                name = col[0].a.string.strip()
                f.write(name+'\n')

            except Exception as e:
                errorFile.write (str(x) + '*********' + str(e) + '********************' + str(col)  +'\n')
                pass

        x = x + 40

    f.close
    errorFile.close

0 个答案:

没有答案