item – Complex Extractor for data extracting.

class data_extractor.item.Field(extractor: data_extractor.abc.SimpleExtractorBase = None, name: str = None, default: Any = sentinel, is_many: bool = False)

Bases: data_extractor.abc.AbstractExtractor

Extract data by cooperating with extractor.

Parameters
  • extractor – The object for data extracting base on data_extractor.abc.SimpleExtractor.

  • name – Optional parameter for special field name.

  • default – Default value when not found. Default: data_extractor.utils.sentinel.

  • is_many – 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 – The target data node element.

Returns

Data or subelement.

Raises

data_extractor.exceptions.ExtractError – Thrown by extractor extracting wrong data.

class data_extractor.item.Item(extractor: data_extractor.abc.SimpleExtractorBase = 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 – The target data node element.

Returns

Data or subelement.

Raises

data_extractor.exceptions.ExtractError – Thrown by extractor extracting wrong data.

classmethod field_names() → Iterator[str]

Iterate all Item or Field type attributes’ name.