views:

36

answers:

0

I am new to python and i have a module that works fine with BeautifulSoup and parses the HTML file, i want to use this module as a function on another file, but i copied almost the exact same code in the funcion but now i get this error: AttributeError: 'NoneType' object has no attribute 'findAll'

Here is the code of the module that works fine

from BeautifulSoup import BeautifulSoup
html=file("file.html")
soup=BeautifulSoup(html)
table=soup.find('table')

records={}
lista=[]

for row in table.findAll('tr')[1:]:
    cols=row.findAll('td')
    team = ''.join((str(cols[1].find(text=True))).upper())
    team=team.replace('.','')
    ptos = str(cols[8].find(text=True))   
    records=dict(team=team,ptos=ptos)
    lista.append(records)

now here is the same code in a function that throws the error:

def parseFile(htmlfile):
    soup=BeautifulSoup(htmlfile)

    table=soup.find('table')
    print table

    records={}
    list=[]
    for row in table.findAll('tr')[1:]: #this line throws the error
        cols=row.findAll('td')
        team = ''.join((str(cols[1].find(text=True))).upper())
        team=team.replace('.','')
        ptos = str(cols[8].find(text=True))   
        records=dict(team=team,ptos=ptos)
        list.append(records)    
    return list

i call the function this way

list1=parseFile(htmlfile)

What am i doing wrong?

thanks for the help