diff options
author | Dalf <alex@al-f.net> | 2019-11-15 09:31:37 +0100 |
---|---|---|
committer | Dalf <alex@al-f.net> | 2019-11-15 09:33:15 +0100 |
commit | 85b37233458c21b775bf98568c0a5c9260aa14fe (patch) | |
tree | 4b79330d170d3f8dbc0c52dadbfef429c31b2187 /searx/engines/duden.py | |
parent | 42d5e2c02cd4715a0e09411efbb249ef5d8defed (diff) | |
download | searxng-85b37233458c21b775bf98568c0a5c9260aa14fe.tar.gz searxng-85b37233458c21b775bf98568c0a5c9260aa14fe.zip |
[mod] speed optimization
compile XPath only once
avoid redundant call to urlparse
get_locale(webapp.py): avoid useless call to request.accept_languages.best_match
Diffstat (limited to 'searx/engines/duden.py')
-rw-r--r-- | searx/engines/duden.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/searx/engines/duden.py b/searx/engines/duden.py index 444f18c1f..cf2f1a278 100644 --- a/searx/engines/duden.py +++ b/searx/engines/duden.py @@ -11,6 +11,7 @@ from lxml import html, etree import re from searx.engines.xpath import extract_text +from searx.utils import eval_xpath from searx.url_utils import quote, urljoin from searx import logger @@ -52,9 +53,9 @@ def response(resp): dom = html.fromstring(resp.text) try: - number_of_results_string = re.sub('[^0-9]', '', dom.xpath( - '//a[@class="active" and contains(@href,"/suchen/dudenonline")]/span/text()')[0] - ) + number_of_results_string =\ + re.sub('[^0-9]', '', + eval_xpath(dom, '//a[@class="active" and contains(@href,"/suchen/dudenonline")]/span/text()')[0]) results.append({'number_of_results': int(number_of_results_string)}) @@ -62,12 +63,12 @@ def response(resp): logger.debug("Couldn't read number of results.") pass - for result in dom.xpath('//section[not(contains(@class, "essay"))]'): + for result in eval_xpath(dom, '//section[not(contains(@class, "essay"))]'): try: - url = result.xpath('.//h2/a')[0].get('href') + url = eval_xpath(result, './/h2/a')[0].get('href') url = urljoin(base_url, url) - title = result.xpath('string(.//h2/a)').strip() - content = extract_text(result.xpath('.//p')) + title = eval_xpath(result, 'string(.//h2/a)').strip() + content = extract_text(eval_xpath(result, './/p')) # append result results.append({'url': url, 'title': title, |