Defining a model

By default, example/items.py contains the following code:

# -*- 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

The ExampleItem class is a template which needs to be replaced with the details we'd like to extract from the example country page. For now, we will just scrape the country name and population, rather than all the country details. Here is an updated model to support this:

class CountryItem(scrapy.Item): 
name = scrapy.Field()
population = scrapy.Field()
Full documentation for defining items is available at http://doc.scrapy.org/en/latest/topics/items.html
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset