help with lists and writing to file in correct order

Kent Johnson kent at kentsjohnson.com
Wed Dec 28 09:06:46 EST 2005


homepricemaps at gmail.com wrote:
> sorry guys, here is the code
> 
>     for incident in bs('a',  {'class' : 'price'}):
>         price = ""
>         for oText in incident.fetchText( oRE):
>               price += oText.strip() + "','"
> 
>     for incident in bs('div',  {'class' : 'store'}):
>         store = ""
>         for oText in incident.fetchText( oRE):
>             store += oText.strip() + "','"
> 
>     for incident in bs('h2',  {'id' : 'food'}):
>       food = ""
>       for oText in incident.fetchText( oRE):
>             food += oText.strip() + "','"
> 

I would use a loop that finds the row for a single item with something like
for item in bs('tr',  {'class' : 'base'}):

then inside the loop fetch the values for store, food and price for that 
item and write them to your output file.

Kent



More information about the Python-list mailing list