L
localpricemaps
i am having a problem writing a tuple to a text file. my code is
below.
what i end up getting is a text file that looks like this
burger, 7up
burger, 7up
burger, 7up
and this is instead of getting a list that should look like this
burger, 7up
fries ,coke
cake ,milk
note that i have print statements that print out the results of the
scraping and they are fine. they print out burger, fries, cake and
then 7up, coke, milk
however there is something faulty in my writing of the tuple to the
text file. perhaps related to the indentation that causes it to write
the same stuff over and over?
for row in bs('div'):
data=[]
for incident in bs('span'):
foodlist = []
b = incident.findPrevious('b')
for oText in b.fetchText( oRE):
#foodlist.append(oText.strip() + "',")
foodlist += oText.strip() + "','"
food = ''.join(foodlist)
print food
for incident in bs('span2'):
drinklist = []
for oText in incident.fetchText( oRE):
drinklist += oText.strip() + "','"
drink = ''.join(drinklist)
print drink
tuple = (food + drink "\n")
data.append(tuple)
f = open("data.txt", 'a')
f.write ( ''.join( tuple ) )
below.
what i end up getting is a text file that looks like this
burger, 7up
burger, 7up
burger, 7up
and this is instead of getting a list that should look like this
burger, 7up
fries ,coke
cake ,milk
note that i have print statements that print out the results of the
scraping and they are fine. they print out burger, fries, cake and
then 7up, coke, milk
however there is something faulty in my writing of the tuple to the
text file. perhaps related to the indentation that causes it to write
the same stuff over and over?
for row in bs('div'):
data=[]
for incident in bs('span'):
foodlist = []
b = incident.findPrevious('b')
for oText in b.fetchText( oRE):
#foodlist.append(oText.strip() + "',")
foodlist += oText.strip() + "','"
food = ''.join(foodlist)
print food
for incident in bs('span2'):
drinklist = []
for oText in incident.fetchText( oRE):
drinklist += oText.strip() + "','"
drink = ''.join(drinklist)
print drink
tuple = (food + drink "\n")
data.append(tuple)
f = open("data.txt", 'a')
f.write ( ''.join( tuple ) )