summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBnyro <bnyro@tutanota.com>2024-07-23 21:20:21 +0200
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-07-27 11:46:25 +0200
commit84abab0808669bb237843e88e725946e74f44642 (patch)
tree659687830557c3907136135b02206e5d839a2d4d
parent8e359eb8edd3428448a5e880b3b62f58c471c545 (diff)
downloadsearxng-84abab0808669bb237843e88e725946e74f44642.tar.gz
searxng-84abab0808669bb237843e88e725946e74f44642.zip
[feat] engine: implementation of geizhals.de
-rw-r--r--docs/dev/engines/online/geizhals.rst8
-rw-r--r--searx/engines/geizhals.py97
-rw-r--r--searx/settings.yml5
3 files changed, 110 insertions, 0 deletions
diff --git a/docs/dev/engines/online/geizhals.rst b/docs/dev/engines/online/geizhals.rst
new file mode 100644
index 000000000..766eb5f59
--- /dev/null
+++ b/docs/dev/engines/online/geizhals.rst
@@ -0,0 +1,8 @@
+.. _gitea geizhals:
+
+========
+Geizhals
+========
+
+.. automodule:: searx.engines.geizhals
+ :members:
diff --git a/searx/engines/geizhals.py b/searx/engines/geizhals.py
new file mode 100644
index 000000000..eae110b20
--- /dev/null
+++ b/searx/engines/geizhals.py
@@ -0,0 +1,97 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+"""Geizhals is a German website to compare the price of a product on the
+most common German shopping sites and find the lowest price.
+
+The sorting of the search results can be influenced by the following additions
+to the search term:
+
+``asc`` or ``price``
+ To sort by price in ascending order.
+
+``desc``
+ To sort by price in descending order.
+
+"""
+
+import re
+
+from urllib.parse import urlencode
+from lxml import html
+
+from searx.utils import eval_xpath, eval_xpath_list, extract_text
+
+about = {
+ 'website': 'https://geizhals.de',
+ 'wikidata_id': 'Q15977657',
+ 'use_official_api': False,
+ 'official_api_documentation': None,
+ 'require_api_key': False,
+ 'results': 'HTML',
+ 'language': 'de',
+}
+paging = True
+categories = ['shopping']
+
+base_url = "https://geizhals.de"
+sort_order = 'relevance'
+
+SORT_RE = re.compile(r"sort:(\w+)")
+sort_order_map = {
+ 'relevance': None,
+ 'price': 'p',
+ 'asc': 'p',
+ 'desc': '-p',
+}
+
+
+def request(query, params):
+ sort = None
+
+ sort_order_path = SORT_RE.search(query)
+ if sort_order_path:
+ sort = sort_order_map.get(sort_order_path.group(1))
+ query = SORT_RE.sub("", query)
+ logger.debug(query)
+
+ args = {
+ 'fs': query,
+ 'pg': params['pageno'],
+ 'toggle_all': 1, # load item specs
+ 'sort': sort,
+ }
+ params['url'] = f"{base_url}/?{urlencode(args)}"
+
+ return params
+
+
+def response(resp):
+ results = []
+
+ dom = html.fromstring(resp.text)
+ for result in eval_xpath_list(dom, "//article[contains(@class, 'listview__item')]"):
+ content = []
+ for spec in eval_xpath_list(result, ".//div[contains(@class, 'specs-grid__item')]"):
+ content.append(f"{extract_text(eval_xpath(spec, './dt'))}: {extract_text(eval_xpath(spec, './dd'))}")
+
+ metadata = [
+ extract_text(eval_xpath(result, ".//div[contains(@class, 'stars-rating-label')]")),
+ extract_text(eval_xpath(result, ".//div[contains(@class, 'listview__offercount')]")),
+ ]
+
+ item = {
+ 'template': 'products.html',
+ 'url': (
+ base_url + "/" + extract_text(eval_xpath(result, ".//a[contains(@class, 'listview__name-link')]/@href"))
+ ),
+ 'title': extract_text(eval_xpath(result, ".//h3[contains(@class, 'listview__name')]")),
+ 'content': ' | '.join(content),
+ 'thumbnail': extract_text(eval_xpath(result, ".//img[contains(@class, 'listview__image')]/@src")),
+ 'price': "Bestes Angebot: "
+ + extract_text(eval_xpath(result, ".//a[contains(@class, 'listview__price-link')]")).split(" ")[1]
+ + "€",
+ 'metadata': ', '.join(item for item in metadata if item),
+ }
+
+ results.append(item)
+
+ return results
diff --git a/searx/settings.yml b/searx/settings.yml
index a26d60026..93abe9566 100644
--- a/searx/settings.yml
+++ b/searx/settings.yml
@@ -797,6 +797,11 @@ engines:
timeout: 8.0
disabled: true
+ - name: geizhals
+ engine: geizhals
+ shortcut: geiz
+ disabled: true
+
- name: genius
engine: genius
shortcut: gen