BeautifulSoup fetch help

ted tedPLEASE-NO-SPAM-95050 at sbcglobal.net
Fri Jan 6 22:45:45 EST 2006


Hi,

I'm using the BeautifulSoup module and having some trouble processing a 
file. It's not printing what I'm expecting. In the code below, I'm expecting 
cells with only "bgcolor" attributes to be printed, but I'm getting cells 
with other attributes and some without any attributes.

Any help appreciated. Thanks,
Ted

import re
from BeautifulSoup import BeautifulSoup

text = open('yahoo.html').read()
soup = BeautifulSoup(text)
tables = soup('table', {'border':re.compile('.+')})

for table in tables:
 cells = table.fetch('td', {'bgcolor':re.compile('.+')})
 for cell in cells:
  print cell
  print "================"






More information about the Python-list mailing list