xpath - Trying to write to a CSV but some fields get excluded in scrapy for python -


i trying write csv when check output, see 'review' fields left blank though there when see output prints correctly. believe zip() limitation using have print column wise rather 10 in row. again xpath output print in spider outputs correctly. im wondering limitaion of zip or syntax? or guess maybe delimeter=','.

pipline.py

import csv import itertools string import maketrans class csvpipeline(object):     def __init__(self):       self.csvwriter = csv.writer(open('output.csv', 'wb'),delimiter=',')       self.csvwriter.writerow(['names','date','location','starts','subjects','reviews'])     def process_item(self, item, ampa):        rows = zip(item['names'],item['date'],item['location'],item['stars'],item['subjects'],item['reviews'])         row in rows:          self.csvwriter.writerow(row)        return item 

sample output, reviews excluded

names,date,location,starts,subjects,reviews aastha2015,20 july 2015," bengaluru (bangalore), india ",5,amazing time in ooty," hi all, visited ooty on july 10th, choose stay in elk hills hotel, read reviews of hotels , decided try elk hills. must property huge, maintained. rooms clean spacious & views great. food in cafe blue awesome. forgot give the... " pushp2015,11 july 2015," gurgaon, india ",3,nice hotel ...under going maintainance," " reddy84,25 june 2015," chennai, india ",4,good old property," old property view. booked suite @ reasonable price charged bed 1500 + txs feel not required because bed in suite room.other good. breakfast nice . room had given neat... " arun606,20 june 2015," mumbai, india ",5,amazing hospitality," " 

i'm not sure think call limitation more zip way of working.

check out izip_longest not stop @ shortest list.

example:

>>> zip('abc', '12345') [('a', '1'), ('b', '2'), ('c', '3')] >>> list(itertools.izip_longest('abc', '12345', fillvalue=0)) [('a', '1'), ('b', '2'), ('c', '3'), (0, '4'), (0, '5')] 

Comments