04-定义模型
[toc]
8.2.1 定义模型
默认情况下, example/items.py
文件包含如下代码。
# -*- coding: utf-8 -*-
# Define here the models for your scraped items
#
# See documentation in:
# http://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()
pass
ExampleItem
类是一个模板,需要将其中的内容替换为我们希望从示例国家(或地区)页面中抽取到的信息。对于目前来说,我们只会抓取国家(或地区)名称和人口数量,而不是抓取国家(或地区)的所有信息。下面是修改后支持该功能的模型代码。
class CountryOrDistrictItem(scrapy.Item):
name = scrapy.Field()
population = scrapy.Field()
定义item的详细文档可以参考 `http://doc.scrapy.org/en/latest/topics/items.html` 。