diff options
| author | Markus Heiser <markus.heiser@darmarit.de> | 2019-12-03 11:38:52 +0100 |
|---|---|---|
| committer | Markus Heiser <markus.heiser@darmarit.de> | 2019-12-03 11:38:52 +0100 |
| commit | 1b90e1403ba832672d8bde02e15a20834ee02e0e (patch) | |
| tree | 09545a498e3fe172cf51cc85ba7c4afe8fba9a3c /searx/utils.py | |
| parent | 52450fd08a3c70f6cc0ef806fc450f70dc867d49 (diff) | |
| parent | 1bb46e5e377dee6a742b1d03876aa188d237bcb2 (diff) | |
Merge branch 'master' of https://github.com/asciimoo/searx into boilerplate
Diffstat (limited to 'searx/utils.py')
| -rw-r--r-- | searx/utils.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/searx/utils.py b/searx/utils.py index e61a134f7..5ea9dc89c 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -13,6 +13,7 @@ from numbers import Number from os.path import splitext, join from io import open from random import choice +from lxml.etree import XPath import sys import json @@ -51,6 +52,7 @@ ecma_unescape2_re = re.compile(r'%([0-9a-fA-F]{2})', re.UNICODE) useragents = json.loads(open(os.path.dirname(os.path.realpath(__file__)) + "/data/useragents.json", 'r', encoding='utf-8').read()) +xpath_cache = dict() lang_to_lc_cache = dict() @@ -450,3 +452,16 @@ def get_engine_from_settings(name): return engine return {} + + +def get_xpath(xpath_str): + result = xpath_cache.get(xpath_str, None) + if result is None: + result = XPath(xpath_str) + xpath_cache[xpath_str] = result + return result + + +def eval_xpath(element, xpath_str): + xpath = get_xpath(xpath_str) + return xpath(element) |