diff options
| author | Noémi Ványi <sitbackandwait@gmail.com> | 2018-02-09 23:52:11 +0100 |
|---|---|---|
| committer | Noémi Ványi <sitbackandwait@gmail.com> | 2020-10-08 13:20:55 +0200 |
| commit | f0278d41fc5cc0d9f618e39be83e690517e64819 (patch) | |
| tree | 25c08217a872fbcaca97dd19ff4fa4014d8a768f /searx | |
| parent | a9dc54bebc943000252975ef25ddcb51681fc284 (diff) | |
add ebay enginte to shopping category
Diffstat (limited to 'searx')
| -rw-r--r-- | searx/engines/ebay.py | 68 | ||||
| -rw-r--r-- | searx/settings.yml | 6 | ||||
| -rw-r--r-- | searx/templates/oscar/result_templates/products.html | 22 |
3 files changed, 96 insertions, 0 deletions
diff --git a/searx/engines/ebay.py b/searx/engines/ebay.py new file mode 100644 index 000000000..e2e5ded6a --- /dev/null +++ b/searx/engines/ebay.py @@ -0,0 +1,68 @@ +# Ebay (Videos, Music, Files) +# +# @website https://www.ebay.com +# @provide-api no (nothing found) +# +# @using-api no +# @results HTML (using search portal) +# @stable yes (HTML can change) +# @parse url, title, content, price, shipping, source + +from lxml import html +from searx.engines.xpath import extract_text +from urllib.parse import quote + +categories = ['shopping'] +paging = True + +url = 'https://www.ebay.com' +search_url = url + '/sch/i.html?_nkw={query}&_sacat={pageno}' + +results_xpath = '//li[contains(@class, "s-item")]' +url_xpath = './/a[@class="s-item__link"]/@href' +title_xpath = './/h3[@class="s-item__title"]' +content_xpath = './/div[@span="SECONDARY_INFO"]' +price_xpath = './/div[contains(@class, "s-item__detail")]/span[@class="s-item__price"][1]/text()' +shipping_xpath = './/span[contains(@class, "s-item__shipping")]/text()' +source_country_xpath = './/span[contains(@class, "s-item__location")]/text()' +thumbnail_xpath = './/img[@class="s-item__image-img"]/@src' + + +def request(query, params): + params['url'] = search_url.format(query=quote(query), pageno=params['pageno']) + return params + + +def response(resp): + results = [] + + dom = html.fromstring(resp.text) + results_dom = dom.xpath(results_xpath) + if not results_dom: + return [] + + for result_dom in results_dom: + url = extract_text(result_dom.xpath(url_xpath)) + title = extract_text(result_dom.xpath(title_xpath)) + content = extract_text(result_dom.xpath(content_xpath)) + price = extract_text(result_dom.xpath(price_xpath)) + shipping = extract_text(result_dom.xpath(shipping_xpath)) + source_country = extract_text(result_dom.xpath(source_country_xpath)) + thumbnail = extract_text(result_dom.xpath(thumbnail_xpath)) + + if title == "": + continue + + results.append({ + 'url': url, + 'title': title, + 'content': content, + 'price': price, + 'shipping': shipping, + 'source_country': source_country, + 'thumbnail': thumbnail, + 'template': 'products.html', + + }) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index 2fbca804f..ae4660f9d 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -235,6 +235,12 @@ engines: shortcut : et disabled : True +# - name : ebay +# engine : ebay +# shortcut : eb +# disabled : True +# timeout: 5 + - name : 1x engine : www1x shortcut : 1x diff --git a/searx/templates/oscar/result_templates/products.html b/searx/templates/oscar/result_templates/products.html new file mode 100644 index 000000000..590db0e05 --- /dev/null +++ b/searx/templates/oscar/result_templates/products.html @@ -0,0 +1,22 @@ +{% from 'oscar/macros.html' import draw_favicon, result_header, result_sub_header, result_footer_rtl, result_footer %} + +{{ result_header(result, favicons) }} +{{ result_sub_header(result) }} + +<div class="container-fluid"> + <div class="row"> + <a href="{{ result.url }}" {% if results_on_new_tab %}target="_blank" rel="noopener noreferrer"{% else %}rel="noreferrer"{% endif %}><img class="thumbnail col-xs-6 col-sm-3 col-md-3 result-content" src="{{ image_proxify(result.thumbnail) }}" alt="{{ result.title|striptags }} {{ result.engine }}" /></a> + <p class="col-xs-12 col-sm-9 col-md-9 result-content"> + {% if result.price %}<big>{{ result.price|safe }}</big></br>{% endif %} + {% if result.shipping %}<small>{{ result.shipping|safe }}</small></br>{% endif %} + {% if result.source_country %}<small>{{ result.source_country|safe }}</small></br>{% endif %} + {% if result.content %}{{ result.content|safe }}{% endif %} + </p> + </div> +</div> + +{% if rtl %} +{{ result_footer_rtl(result) }} +{% else %} +{{ result_footer(result) }} +{% endif %} |