Parsel Documentation, Release 1.9.1
remove() → None
Remove matched nodes from the parent for each element in this list.
xpath(xpath: str, namespaces: Mapping[str, str] | None = None, **kwargs: Any) →
SelectorList[_SelectorType]
Call the .xpath() method for each element in this list and return their results flattened as another
SelectorList.
xpath is the same argument as the one in Selector.xpath()
namespaces is an optional prefix: namespace-uri mapping (dict) for additional prefixes to those reg-
istered with register_namespace(prefix, uri). Contrary to register_namespace(), these pre-
fixes are not saved for future calls.
Any additional named arguments can be used to pass values for XPath variables in the XPath expression,
e.g.:
selector.xpath('//a[href=$url]', url="http://www.example.com")
parsel.selector.create_root_node(text: str, parser_cls: Type[XMLParser | HTMLParser], base_url: str |
None = None, huge_tree: bool = True, body: bytes = b'', encoding: str =
'utf8') → _Element
Create root node for text using given parser class.
1.3.3 parsel.utils
parsel.utils.extract_regex(regex: str | Pattern[str], text: str, replace_entities: bool = True) → List[str]
Extract a list of strings from the given text/encoding using the following policies: * if the regex contains a named
group called “extract” that will be returned * if the regex contains multiple numbered groups, all those will be
returned (flattened) * if the regex doesn’t contain any group the entire regex matching is returned
parsel.utils.flatten(sequence) → list
Returns a single, flat list which contains all elements retrieved from the sequence and all recursively contained
sub-sequences (iterables). Examples: >>> [1, 2, [3,4], (5,6)] [1, 2, [3, 4], (5, 6)] >>> flatten([[[1,2,3], (42,None)],
[4,5], [6], 7, (8,9,10)]) [1, 2, 3, 42, None, 4, 5, 6, 7, 8, 9, 10] >>> flatten([“foo”, “bar”]) [‘foo’, ‘bar’] >>>
flatten([“foo”, [“baz”, 42], “bar”]) [‘foo’, ‘baz’, 42, ‘bar’]
parsel.utils.iflatten(sequence) → Iterator
Similar to .flatten(), but returns iterator instead
parsel.utils.shorten(text: str, width: int, suffix: str = '...') → str
Truncate the given text to fit in the given width.
1.4 History
1.4.1 1.9.1 (2024-04-08)
• Removed the dependency on pytest-runner.
• Removed the obsolete Makefile.
1.4. History 27