Thanks Mike, works like a charm. -Ted
"Mike Meyer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "ted" <[EMAIL PROTECTED]> writes: > >> 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. > > BeatifulSoups matching is for any tag with a matching attribute, not > tags that only match that attribute. That's why you're getting tags > with other attributes. > > However, you can use a callable as the tag argument to check for what > you want: > > def findtagswithly(name, attr): > return (lambda tag: tag.name == name and > len(tag.attrs) == 1 and > tag.attrs[0][0] == attr) > > ... > > cells = table.fetch(findtagswithonly('a', 'bgcolor')) > > > Or, because I wrote it to check out: > > def findtagswithoneattrib(name): > return lambda tag: tag.name == name and len(tag.attrs) == 1 > > ... > cells = table.fetch(findtagswithoneattrib('a', {bgcolor: > re.compile('.+)})) > > I'm not sure why you're getting tags without attributes. If the above > code does that, post some sample data along with the code. > > <mike > -- > Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ > Independent WWW/Perforce/FreeBSD/Unix consultant, email for more > information. -- http://mail.python.org/mailman/listinfo/python-list