From d2f736c82760daf7ee232d5a09b3a09ed8ba4692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E7=8E=AE?= Date: Sun, 19 May 2019 12:06:01 +0800 Subject: [PATCH] Update docs --- data_extractor/abc.py | 2 +- data_extractor/exceptions.py | 2 +- data_extractor/utils.py | 4 ++-- docs/source/quickstarts.rst | 19 +++++++++++-------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/data_extractor/abc.py b/data_extractor/abc.py index 5c3df63..f26a4a2 100644 --- a/data_extractor/abc.py +++ b/data_extractor/abc.py @@ -84,7 +84,7 @@ def extract(self, element: Any) -> Any: :param element: The target data node element. - :returns: Data or subelement + :returns: Data or subelement. """ raise NotImplementedError diff --git a/data_extractor/exceptions.py b/data_extractor/exceptions.py index d4af96a..d10c0d6 100644 --- a/data_extractor/exceptions.py +++ b/data_extractor/exceptions.py @@ -14,7 +14,7 @@ class ExprError(Exception): """ - Invalid Expr + Invalid Expr. :param extractor: The object for data extracting base on :class:`data_extractor.abc.AbstractExtractor`. :param exc: The actual exception is thrown when extracting. diff --git a/data_extractor/utils.py b/data_extractor/utils.py index b12037f..10e1955 100644 --- a/data_extractor/utils.py +++ b/data_extractor/utils.py @@ -7,7 +7,7 @@ class __Sentinel: - """ Singleton """ + """ Singleton. """ def __repr__(self) -> str: return "sentinel" @@ -18,7 +18,7 @@ def __repr__(self) -> str: class LazyStr: """ - Lazy String + Lazy String. :param func: Lazy __str__ function. """ diff --git a/docs/source/quickstarts.rst b/docs/source/quickstarts.rst index fadedcf..813212d 100644 --- a/docs/source/quickstarts.rst +++ b/docs/source/quickstarts.rst @@ -4,6 +4,8 @@ Quickstarts Installation ------------ +.. code-block:: shell + pip install data-extractor Usage @@ -17,6 +19,8 @@ HTML or XML data Download RSS Sample file +.. code-block:: shell + wget http://www.rssboard.org/files/sample-rss-2.xml Parse it into :class:`data_extractor.lxml.Element`. @@ -33,7 +37,7 @@ Using :class:`data_extractor.lxml.XPathExtractor` to extract rss channel title. .. code-block:: python3 - from data_extractor.lxml import XPathExtractor + from data_extractor import XPathExtractor XPathExtractor("//channel/title/text()").extract_first(root) @@ -48,7 +52,7 @@ to extract all rss item links. .. code-block:: python3 - from data_extractor.lxml import TextCSSExtractor + from data_extractor import TextCSSExtractor TextCSSExtractor("item>link").extract(root) @@ -65,7 +69,7 @@ Using :class:`data_extractor.lxml.AttrCSSExtractor` to extract rss version. .. code-block:: python3 - from data_extractor.lxml import AttrCSSExtractor + from data_extractor import AttrCSSExtractor AttrCSSExtractor("rss", attr="version").extract_first(root) @@ -88,7 +92,7 @@ Using :class:`data_extractor.json.JSONExtractor` to extract data. .. code-block:: python3 - from data_extractor.json import JSONExtractor + from data_extractor import JSONExtractor JSONExtractor("foo[*].baz").extract(data) @@ -106,8 +110,7 @@ then extracting the data. .. code-block:: python3 - from data_extractor.item import Field, Item - from data_extractor.lxml import XPathExtractor + from data_extractor import Field, Item, XPathExtractor class ChannelItem(Item): title = Field(XPathExtractor("./title/text()"), default="") @@ -134,7 +137,7 @@ Extracting the rss data from file .. code-block:: python3 - from data_extractor.lxml import XPathExtractor + from data_extractor import XPathExtractor Channel(XPathExtractor("//channel")).extract(root) @@ -190,7 +193,7 @@ Or just extracting the channel item from file. .. code-block:: python3 - from data_extractor.lxml import XPathExtractor + from data_extractor import XPathExtractor ChannelItem(XPathExtractor("//channel/item"), is_many=True).extract(root)