Scrapy组件之item
Scrapy是一个流行的网络爬虫框架,从现在起将陆续记录Python3.6下Scrapy整个学习过程,方便后续补充和学习。 Python网络爬虫之scrapy(一) 已经介绍scrapy安装、项目创建和测试基本命令操作,本文将对item设置、提取和使用进行详细说明 item设置 item是保存爬取到的数据的容器,其使用方式和字典类似,并且提供了额外保护机制来避免拼写错误导致的未定义字段错误,定义类型为scrapy.Field的类属性来定义一个item,可以根据自己的需要在items.py文件中编辑相应的item # -*- coding: utf-8 -*- # Define here the models for your scraped items # # See documentation in: # https://doc.scrapy.org/en/latest/topics/items.html #装载我们抓取数据的容器 import scrapy class ExampleItem(scrapy.Item): # define the fields for your item here like: # name = scrapy.Field() name = scrapy.Field() #属性作为Field对象 population = scrapy.Field