Scrapy, a fast high-level web crawling & scraping framework for Python.
relocated experimental newitems/loaders doc, and added example for extending fields metadata
Pablo Hoffmane585c6cac4a2
diff --git a/docs/experimental/index.rst b/docs/experimental/index.rstindex e8bd7a50f..55468737d 100644--- a/docs/experimental/index.rst+++ b/docs/experimental/index.rst@@ -19,5 +19,5 @@ it's properly merged) . Use at your own risk... toctree:::maxdepth: 1- newitem- newitem-loader+ newitems+ loadersdiff --git a/docs/experimental/newitem-loader.rst b/docs/experimental/loaders.rstsimilarity index 97%rename from docs/experimental/newitem-loader.rstrename to docs/experimental/loaders.rstindex 61d8d71fb..c66b4448b 100644--- a/docs/experimental/newitem-loader.rst+++ b/docs/experimental/loaders.rst@@ -8,12 +8,12 @@ Item Loaders:synopsis: Item Loader classItem Loaders (or Loaders, for short) provide a convenient mechanism for-populating scraped :ref:`Items <topics-newitem>`. Even though Items can be+populating scraped :ref:`Items <topics-newitems>`. Even though Items can bepopulated using their own dictionary-like API, the Loaders provide a much moreconvenient API for populating them from a scraping process, by automating somecommon tasks like parsing the raw extracted data before assigning it.-In other words, :ref:`Items <topics-newitem>` provide the *container* of+In other words, :ref:`Items <topics-newitems>` provide the *container* ofscraped data, while Loaders provide the mechanism for *populating* thatcontainer.@@ -34,8 +34,8 @@ Then, you start adding values to the Loader, typically collecting them usingsame item field, the Loader will know how to "join" those values later using aReducer.-Here's a typical Loader usage in a :ref:`Spider <topics-spiders>` the-:ref:`Product item defined in the Items chapter <topics-newitem-declaring>`.::+Here is a typical Loader usage in a :ref:`Spider <topics-spiders>` using the+:ref:`Product item defined in the Items chapter <topics-newitems-declaring>`.::from scrapy.item.loader import Loaderfrom scrapy.xpath import HtmlXPathSelectordiff --git a/docs/experimental/newitem.rst b/docs/experimental/newitems.rstsimilarity index 92%rename from docs/experimental/newitem.rstrename to docs/experimental/newitems.rstindex ec5c2149e..0cd3c88ba 100644--- a/docs/experimental/newitem.rst+++ b/docs/experimental/newitems.rst@@ -1,8 +1,8 @@-.. _topics-newitem:+.. _topics-newitems:-=====-Items-=====+=================+Items (version 2)+=================.. module:: scrapy.newitem:synopsis: Item and Field classes@@ -17,7 +17,7 @@ their available fields... _dictionary-like: http://docs.python.org/library/stdtypes.html#dict-.. _topics-newitem-declaring:+.. _topics-newitems-declaring:Declaring Items===============@@ -204,6 +204,15 @@ For example::discount_percent = Field(default=0)discount_expiration_date = Field()+You can also extend field metadata by using the previous field metadata and+appending more values, or changing existing values, like this::++ class SpecificProduct(Product):+ name = Field(Product.fields['name'], default='product')++That adds (or replaces) the ``default`` metadata key for the ``name`` field,+keeping all the previously existing metadata values.+Item objects============@@ -219,7 +228,7 @@ Item objectsA dictionary containing *all declared fields* for this Item, not onlythose populated. The keys are the field names and the values are the:class:`Field` objects used in the :ref:`Item declaration- <topics-newitem-declaring>`.+ <topics-newitems-declaring>`... _dict API: http://docs.python.org/library/stdtypes.html#dict@@ -231,7 +240,7 @@ Field objectsThe :class:`Field` class is just an alias to the built-in `dict`_ class anddoesn't provide any extra functionality or attributes. In other words,:class:`Field` objects are plain-old Python dicts. A separate class is used- to support the :ref:`item declaration syntax <topics-newitem-declaring>`+ to support the :ref:`item declaration syntax <topics-newitems-declaring>`based on class attributes... _dict: http://docs.python.org/library/stdtypes.html#dict