2009-01-04 15:37:43 +00:00
|
|
|
.. _topics-items:
|
|
|
|
|
2009-01-05 16:55:20 +00:00
|
|
|
=====
|
|
|
|
Items
|
|
|
|
=====
|
|
|
|
|
|
|
|
Quick overview
|
|
|
|
==============
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-30 13:05:52 +00:00
|
|
|
In Scrapy, items are the placeholder to use for the scraped data. They are
|
|
|
|
represented by a :class:`ScrapedItem` object, or any descendant class instance,
|
2009-01-30 21:52:41 +00:00
|
|
|
and store the information in instance attributes.
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-05 16:55:20 +00:00
|
|
|
ScrapedItems
|
|
|
|
============
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-29 17:46:32 +00:00
|
|
|
.. module:: scrapy.item
|
|
|
|
:synopsis: Objects for storing scraped data
|
|
|
|
|
2009-01-05 16:55:20 +00:00
|
|
|
.. class:: ScrapedItem
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-05 16:55:20 +00:00
|
|
|
Methods
|
|
|
|
-------
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-29 17:46:32 +00:00
|
|
|
.. method:: ScrapedItem.__init__(data=None)
|
2009-01-05 16:55:20 +00:00
|
|
|
|
2009-01-30 13:05:52 +00:00
|
|
|
:param data: A dictionary containing attributes and values to be set
|
|
|
|
after instancing the item.
|
2009-01-05 16:55:20 +00:00
|
|
|
|
2009-01-30 13:05:52 +00:00
|
|
|
Instanciates a ``ScrapedItem`` object and sets an attribute and its value
|
|
|
|
for each key in the given ``data`` dict (if any). These items are the most
|
|
|
|
basic items available, and the common interface from which any items should
|
|
|
|
inherit.
|
2009-01-05 16:55:20 +00:00
|
|
|
|
2009-01-29 17:46:32 +00:00
|
|
|
Examples
|
|
|
|
--------
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-29 17:46:32 +00:00
|
|
|
Creating an item and setting some attributes::
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-29 17:46:32 +00:00
|
|
|
>>> from scrapy.item import ScrapedItem
|
|
|
|
>>> item = ScrapedItem()
|
|
|
|
>>> item.name = 'John'
|
|
|
|
>>> item.last_name = 'Smith'
|
|
|
|
>>> item.age = 23
|
|
|
|
>>> item
|
|
|
|
ScrapedItem({'age': 23, 'last_name': 'Smith', 'name': 'John'})
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-29 17:46:32 +00:00
|
|
|
Creating an item and setting its attributes inline::
|
2009-01-04 15:37:43 +00:00
|
|
|
|
2009-01-29 17:46:32 +00:00
|
|
|
>>> person = ScrapedItem({'name': 'John', 'age': 23, 'last_name': 'Smith'})
|
|
|
|
>>> person
|
|
|
|
ScrapedItem({'age': 23, 'last_name': 'Smith', 'name': 'John'})
|
2009-01-04 15:37:43 +00:00
|
|
|
|