MCPcopy
hub / github.com/searx/searx / eval_xpath

Function eval_xpath

searx/utils.py:541–562  ·  view source on GitHub ↗

Equivalent of element.xpath(xpath_str) but compile xpath_str once for all. See https://lxml.de/xpathxslt.html#xpath-return-values Args: * element (ElementBase): [description] * xpath_spec (str|lxml.etree.XPath): XPath as a str or lxml.etree.XPath Returns: * resu

(element, xpath_spec)

Source from the content-addressed store, hash-verified

539
540
541def eval_xpath(element, xpath_spec):
542 """Equivalent of element.xpath(xpath_str) but compile xpath_str once for all.
543 See https://lxml.de/xpathxslt.html#xpath-return-values
544
545 Args:
546 * element (ElementBase): [description]
547 * xpath_spec (str|lxml.etree.XPath): XPath as a str or lxml.etree.XPath
548
549 Returns:
550 * result (bool, float, list, str): Results.
551
552 Raises:
553 * TypeError: Raise when xpath_spec is neither a str nor a lxml.etree.XPath
554 * SearxXPathSyntaxException: Raise when there is a syntax error in the XPath
555 * SearxEngineXPathException: Raise when the XPath can't be evaluated.
556 """
557 xpath = get_xpath(xpath_spec)
558 try:
559 return xpath(element)
560 except XPathError as e:
561 arg = ' '.join([str(i) for i in e.args])
562 raise SearxEngineXPathException(xpath_spec, arg) from e
563
564
565def eval_xpath_list(element, xpath_spec, min_len=None):

Callers 15

responseFunction · 0.90
responseFunction · 0.90
responseFunction · 0.90
responseFunction · 0.90
responseFunction · 0.90
responseFunction · 0.90
responseFunction · 0.90
scrap_out_thumbsFunction · 0.90
responseFunction · 0.90
responseFunction · 0.90
responseFunction · 0.90

Calls 2

get_xpathFunction · 0.85

Tested by

no test coverage detected