pipelines中的代码如下所示
import openpyxl
class ZufangzPipeline:
def __init__(self):
self.wb=openpyxl.Workbook()
self.ws=self.wb.active
self.ws.append(['total','unitPriceValue','qu_yu', 'hu_xing', 'lou_ceng', 'mian_ji', 'zhuang_xiu', 'gong_nuan', 'chan_quan',
'yong_tu', 'nian_xian', 'di_ya'])
def process_item(self, item, spider):
line = [item['total'], item['unitPriceValue'], item['qu_yu'], item['hu_xing'], item['lou_ceng'], item['mian_ji'], item['zhuang_xiu'],
item['gong_nuan'], item['chan_quan'], item['yong_tu'], item['nian_xian'], item['di_ya']]
self.ws.append(line)
return item
def close_spider(self,spider):
self.wb.save('house.xlsx')
self.wb.close()
settings中的设置如下:
ITEM_PIPELINES = {
'zufangz.pipelines.ZufangzPipeline': 300,
}