BeautifulSoup fetch help

ted tedPLEASE-NO-SPAM-95050 at
Sat Jan 7 04:45:45 CET 2006


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,

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