一.何时用到
数据格式为csv时,抓取数据需要用到 如http://yum.iqianyue.com/weisuenbook/pyspd/part12/mydata.csv
二.如何玩
打开网站是csv下载文件,下载后为
用记事本打开后
三.上代码
scrapy startproject csvspider
cd csvspider
scrapy genspider -t csvfeed mycsvspider iqianyue.com
# -*- coding: utf-8 -*- from scrapy.spiders import CSVFeedSpider class MycsvspiderSpider(CSVFeedSpider): name = 'mycsvspider' allowed_domains = ['iqianyue.com'] start_urls = ['http://yum.iqianyue.com/weisuenbook/pyspd/part12/mydata.csv'] headers = ['name', 'sex', 'addr', 'email'] delimiter = ',' # Do any adaptations you need here #def adapt_response(self, response): # return response def parse_row(self, response, row): i = {} i['name'] = row['name'] i['sex'] = row['sex'] print u'名字是:'+ i['name'] print u'性别是:'+ i['sex'] print '--'*8 return iheaders为csv的表头信息
delimiter为每行的分隔符“,”