E
E
exded2017-03-25 10:04:08
Python
exded, 2017-03-25 10:04:08

Python only writes first value to csv file?

I wrote a parser, but why do I have img and the sizes write in csv go to rows, not columns, how to make it write to rows?
My data is parsed like this
a5f5e0d6e21249d4bf9ba5e24ed1ad6c.png
now
51609ccd2eed424aa1960e2f45accc22.png

bb_strings = re.findall(r'var model = ({.*})', ad)
bp = {}
if bb_strings:
    bp = json.loads(bb_strings[0])
    
     for bl in bp['AVAILABLE_SIZES']:
         footlocker.append(('размер', bl))

and the code that is responsible for parsing images and saving data
for k in d['set']['item']:
 dd = '{url}{ext}{end}'.format(url=imgurg, ext=k['i']['n'], end='?id=Y6YPH3?&wid=1280&hei=877&fmt.png')
           t = requests.get(dd)
           out = open('images/%s' % dd.split('/')[-1], 'wb')
           out.write(t.content)
           footlocker.append(('images', dd.split('/')[-1]))
           out.close()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
exded, 2017-03-28
@exded

razmer = 0
 bb_strings = re.findall(r'var model = ({.*})', ad)
 bp = {}
 if bb_strings:
 bp = json.loads(bb_strings[0])
     for bl in bp['AVAILABLE_SIZES']:
     razmer +=1
     footlocker.append(('razmer%s' %razmer, bl))

D
Dimonchik, 2017-03-25
@dimonchik2013

explicit is better than implicit - forgot?
or file mode ( 'wb') switch to append (ab)
or all to a list of lists and then to the file the
second is more correct

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question