need help with python syntax

Mike Meyer mwm at mired.org
Sun Dec 25 06:29:51 CET 2005


homepricemaps at gmail.com writes:
> if i have a piece of html that looks like this
> <tr class="rulesbody">
> <td width="183" class="rulesbody">cnn.com
> and i want to scrape out cnn.com , what syntax would i use?  i have
> tried this and it doesn't work
> for incident in bs('td', {'class' : 'rulesbody'}, {'class' :
> 'rulesbody'} ):

If you're using BeautifulSoup, you don't need to pass in the second
dictionary. For that matter, you don't need to pass in the first one -
bs.fetch (which is what calling a tag object calls) will treat a
bare string as a request for a class. On the other hand, I don't like
using the callable objecdt shortcut, and prefer spelling out fetch
explicitly. So you'd write:

for incident in bs.fetch('td', 'rulesbody'):

   <mike


-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list