Items
Item objects are simple containers used to collect the scraped data.They provide a dictionary-like api with a convenient syntax for declaring their available fields.
import scrapy;
class Product(scrapy.Item):
name=scrapy.Field()
price=scrapy.Field()
stock=scrapy.Field()
last_updated=scrapy.Field(serializer=str)
Extending Items
you can extend Items(to add more fields or to change some metadata for some fields)by declaring a subclass of your original Item.
class DiscountedProduct(Product):
discount_percent=scrapy.Field(serializer=str)
You can also extend fields metadata by using the previous field metadata and appending more values,or changind existing values.
class SpecificProduct(Product):
name=scrapy.Field(Product.fields[‘name‘],serializer=my_serializer)
Item Objects
1.class scrapy.item.Item([arg])
Return a new Item optionally initialized from the given argument
The only additional attribute provided by Items is:fields
2.Field objects
class scrapy.item.Field([arg])
The Field class is just an alias to the built-in dict class and doesn‘t provide any extra functionality or attributes.
【scrapy】基础知识