help with lists and writing to file in correct order

homepricemaps at gmail.com homepricemaps at gmail.com
Thu Dec 29 15:45:07 EST 2005


hey kent thanks for your help.

so i ended up using a loop but find that i end up getting the same set
of results every time.  the code is here:

    for incident in bs('tr'):
	data2 = []
    	for incident in bs('h2',  {'id' : 'dealName'}):
        	product2 = ""
		for oText in incident.fetchText( oRE):
            		product2 += oText.strip() + ';'



      	for incident in bs('a',  {'name' : 'D0L3'}):
        	store2 = ""
		for oText in incident.fetchText( oRE):
            		store2 += oText.strip() + ';'


    	for incident in bs('a',  {'class' : 'nojs'}):
        	price2 = ""
		for oText in incident.fetchText( oRE):
            		price2 += oText.strip() + ';'


	tuple2 = (product2, store2, price2)
	data2.append(tuple2)
	print data2

and i end up getting the following instead of unique results

pizza, pizzahut, 3.94
pizza, pizzahut, 3.94
pizza, pizzahut, 3.94
pizza, pizzahut, 3.94
>
> 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