爬虫整个过程中,需要蜘蛛,调度器,下载器,管道 的配合,才能真正完成整个操作,今天就来说一说这个过程以及编码和使用过程:
本章主要了解一下item和pipline的运用
(注意:在使用item的前提是,将setting文件中的ITEM_PIPELINES释放)
ITEM_PIPELINES ={'kgc.pipelines.KgcPipeline': 300,
}
代码预览:
spider.py
importscrapyfrom kgc.items import *
classKgcspideSpider(scrapy.Spider):
name= 'kgcspide'
start_urls = ['http://www.kgc.cn/list/230-1-6-9-9-0.shtml']defparse(self, response):
title = response.css('a.yui3-u.course-title-a.ellipsis::text').extract()
price=response.css('div.right.align-right>span::text').extract()
persons=response.css('span.course-pepo::text').extract()
datas=zip(title,price,persons)for d indatas:
item=KgcItem()
item['title']=d[0]