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/duckduckgo.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/duckduckgo.py')
-rw-r--r-- | searx/engines/duckduckgo.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/searx/engines/duckduckgo.py b/searx/engines/duckduckgo.py index e77ef0126..0d2c0af2d 100644 --- a/searx/engines/duckduckgo.py +++ b/searx/engines/duckduckgo.py @@ -18,7 +18,7 @@ from json import loads from searx.engines.xpath import extract_text from searx.poolrequests import get from searx.url_utils import urlencode -from searx.utils import match_language +from searx.utils import match_language, eval_xpath # engine dependent config categories = ['general'] @@ -106,19 +106,19 @@ def response(resp): doc = fromstring(resp.text) # parse results - for i, r in enumerate(doc.xpath(result_xpath)): + for i, r in enumerate(eval_xpath(doc, result_xpath)): if i >= 30: break try: - res_url = r.xpath(url_xpath)[-1] + res_url = eval_xpath(r, url_xpath)[-1] except: continue if not res_url: continue - title = extract_text(r.xpath(title_xpath)) - content = extract_text(r.xpath(content_xpath)) + title = extract_text(eval_xpath(r, title_xpath)) + content = extract_text(eval_xpath(r, content_xpath)) # append result results.append({'title': title, |