码迷,mamicode.com
首页 > 其他好文 > 详细

【scrapy】基础知识

时间:2014-07-16 22:48:37      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   for   cti   re   

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】基础知识,布布扣,bubuko.com

【scrapy】基础知识

标签:style   color   io   for   cti   re   

原文地址:http://www.cnblogs.com/ljygoodgoodstudydaydayup/p/3835542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!