mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
add google shopping engine
This commit is contained in:
parent
8177bf3f0a
commit
8e876ad9ff
2 changed files with 63 additions and 0 deletions
59
searx/engines/google_shopping.py
Normal file
59
searx/engines/google_shopping.py
Normal file
|
@ -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
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue