diff --git a/searx/engines/google_shopping.py b/searx/engines/google_shopping.py new file mode 100644 index 000000000..bd15c78b8 --- /dev/null +++ b/searx/engines/google_shopping.py @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +""" + Google Shopping +""" + +from urllib.parse import urlencode +from lxml import html +from searx.utils import extract_text + +about = { + "website": "https://shopping.google.com", + "wikidata_id": "Q1433417", + "use_official_api": False, + "require_api_key": False, + "results": "HTML", +} + +categories = ["shopping"] +paging = True + +search_url = "https://shopping.google.com/search?{query}&tbm=shop&start={pageno}" + +results_xpath = '//div[@class="op4oU"]/div[@role="listitem" and @style=""]' +title_xpath = './/h2[@class="MPhl6c pqv9ne azTb0d ulfEhd YAEPj XkyFEf"]' +url_xpath = './/a[@class="loT5Qd kneS6c"]/@href' +price_xpath = './/span[@class="aZK3gc Lhpu7d"]' +thumbnail_xpath = './/img[@class="Ws3Esf"]/@src' + + +def request(query, params): + pageno = (params["pageno"] - 1) * 60 + params["url"] = search_url.format(query=urlencode({"q": query}), pageno=pageno) + + return params + + +def response(resp): + results = [] + + dom = html.fromstring(resp.text) + + res = dom.xpath(results_xpath) + for result in res: + url = extract_text(result.xpath(url_xpath)) + title = extract_text(result.xpath(title_xpath)) + price = extract_text(result.xpath(price_xpath)) + thumbnail = extract_text(result.xpath(thumbnail_xpath)) + + results.append( + { + "url": url, + "title": title, + "price": price, + "thumbnail": thumbnail, + "template": "products.html", + } + ) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 709e43627..195407333 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -739,6 +739,10 @@ engines: require_api_key: false results: HTML + - name: google shopping + engine: google_shopping + shortcut: gsh + - name: gpodder engine: json_engine shortcut: gpod