item
– Complex Extractor for data extracting.¶
-
class
data_extractor.item.
Field
(extractor: data_extractor.core.AbstractSimpleExtractor = None, name: str = None, default: Any = sentinel, is_many: bool = False)¶ Bases:
data_extractor.core.AbstractComplexExtractor
Extract data by cooperating with extractor.
- Parameters
extractor (
data_extractor.core.AbstractSimpleExtractor
) – The object for data extractingname (str, optional) – Optional parameter for special field name.
default (Any) – Default value when not found. Default:
data_extractor.utils.sentinel
.is_many (bool) – Indicate the data which extractor extracting is more than one.
- Raises
ValueError – Invalid SimpleExtractor.
ValueError – Can’t both set default and is_manay=True.
-
extract
(element: Any) → Any¶ Extract the wanted data.
- Parameters
element (Any) – The target data node element.
- Returns
Data or subelement.
- Return type
Any
- Raises
ExtractError – Thrown by extractor extracting wrong data.
-
class
data_extractor.item.
Item
(extractor: data_extractor.core.AbstractSimpleExtractor = None, name: str = None, default: Any = sentinel, is_many: bool = False)¶ Bases:
data_extractor.item.Field
Extract data by cooperating with extractors, fields and items.
-
extract
(element: Any) → Any¶ Extract the wanted data.
- Parameters
element (Any) – The target data node element.
- Returns
Data or subelement.
- Return type
Any
- Raises
ExtractError – Thrown by extractor extracting wrong data.
-
classmethod
field_names
() → Iterator[str]¶ Iterate all Item or Field type attributes’ name.
-
simplify
() → data_extractor.core.AbstractSimpleExtractor¶ Create an extractor that has compatible API like SimpleExtractor’s.
- Returns
A simple extractor.
- Return type
-