[Tutor] returning table elements with Beautiful Soup
Bill Kranec
billk at fastmail.fm
Sat Mar 5 05:05:53 CET 2005
Hi,
I'm trying to use Beautiful Soup to scrape some data out of an HTML
table. I can do this using
table = soup("td", {'class' : 'yfnc_tabledata1' })
table[0].string.strip()
However, if I try
for entry in table:
entry.string.strip()
I get: AttributeError: Tag instance has no attribute 'string'
Clearly Python is now treating the cell as a list element, not as a
Beautiful Soup class, so it cannot find the method that I want to use.
But I can't seem to find a way to do what I meant to do.
Is there an easy way to have Beautiful Soup return each data element in
the table, preferably into a list?
Any help is greatly appreciated.
Bill
More information about the Tutor
mailing list