我有从网站上抓取的项目,我将它们放入如下的 json 文件中
{
"author": ["TIM ROCK"],
"book_name": ["Truk Lagoon, Pohnpei & Kosrae Dive Guide"],
"category": "Travel",
}
{
"author": ["JOY"],
"book_name": ["PARSER"],
"category": "Accomp",
}
我想将它们存储在 csv 文件中,每行一个字典,其中每列一个项目如下
| author | book_name | category |
| TIM ROCK | Truk Lagoon ... | Travel |
| JOY | PARSER | Accomp |
我在一行中获取一本字典的项目,但所有列都组合在一起
我的pipeline.py
代码是
导入 csv
class Blurb2Pipeline(object):
def __init__(self):
self.brandCategoryCsv = csv.writer(open('blurb.csv', 'wb'))
self.brandCategoryCsv.writerow(['book_name', 'author','category'])
def process_item(self, item, spider):
self.brandCategoryCsv.writerow([item['book_name'].encode('utf-8'),
item['author'].encode('utf-8'),
item['category'].encode('utf-8'),
])
return item