在讲解pipelines之前,我先举个例子,这样好了解爬取数据的具体过程:
- 发送请求
- 获取到数据(从网站上爬取了数据)
- 数据清洗(处理数据)
- 存储(把数据存储起来)
而现在,我介绍一下pipelines,它可以负责的就是第3和第4步的工作,专业述语就是管道。我们通过定义一个或多个class,可以用来处理我们传入的数据。
代码目录:
爬虫代码 mingyan_spider.py:
import scrapy
def getUrl():
return 'https://search.51job.com/list/030200,000000,0000,00,9,99,%2520,2,1.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99°reefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=