Question

I am trying to find the tr tag from the financialStatement table. Everything works fine until I code the last line rows = statement.findAll ( 'tr' ), which gives:

AttributeError: 'NoneType' object has no attribute 'findAll'

Here the html file: http://investing.businessweek.com/research/stocks/financials/financials.asp?ticker=TSCO:LN

import os
import urllib,re
from BeautifulSoup import BeautifulSoup 

path = '/Users/projectfile/'
listing = os.listdir(path)

for infile in listing:
    print "current file is: " + infile
    fileIN = open(path+infile, "r")
    line = fileIN.read()
    soup = BeautifulSoup ( line )
    statement = soup.find ( 'table' , { 'class' : "financialStatement" })
    rows = statement.findAll ( 'tr' )
Was it helpful?

Solution

It means that statement in None. So probably this line: soup.find ( 'table' , { 'class' : "financialStatement" }) doesn't find anything and returns None.

You could add an if statement to test if statement has a value:

if statement:
   rows = statement.findAll ( 'tr' )
else:
   rows = None
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top