on master help sign in
add ebay enginte to shopping category
commitf0278d41fc5cc0d9f618e39be83e690517e64819 authorNoémi Ványi <sitbackandwait@gmail.com> dateFri 9 Feb 2018, 23:52 (9 years ago) parenta9dc54b
3 files changed+96
searx/engines/ebay.py+68 searx/settings.yml+6 searx/templates/oscar/result_templates/products.html+22
searx/engines/ebay.pynew file+68
@@ -0,0 +1,68 @@
1+# Ebay (Videos, Music, Files)
2+#
3+# @website https://www.ebay.com
4+# @provide-api no (nothing found)
5+#
6+# @using-api no
7+# @results HTML (using search portal)
8+# @stable yes (HTML can change)
9+# @parse url, title, content, price, shipping, source
10+
11+from lxml import html
12+from searx.engines.xpath import extract_text
13+from urllib.parse import quote
14+
15+categories = ['shopping']
16+paging = True
17+
18+url = 'https://www.ebay.com'
19+search_url = url + '/sch/i.html?_nkw={query}&_sacat={pageno}'
20+
21+results_xpath = '//li[contains(@class, "s-item")]'
22+url_xpath = './/a[@class="s-item__link"]/@href'
23+title_xpath = './/h3[@class="s-item__title"]'
24+content_xpath = './/div[@span="SECONDARY_INFO"]'
25+price_xpath = './/div[contains(@class, "s-item__detail")]/span[@class="s-item__price"][1]/text()'
26+shipping_xpath = './/span[contains(@class, "s-item__shipping")]/text()'
27+source_country_xpath = './/span[contains(@class, "s-item__location")]/text()'
28+thumbnail_xpath = './/img[@class="s-item__image-img"]/@src'
29+
30+
31+def request(query, params):
32+ params['url'] = search_url.format(query=quote(query), pageno=params['pageno'])
33+ return params
34+
35+
36+def response(resp):
37+ results = []
38+
39+ dom = html.fromstring(resp.text)
40+ results_dom = dom.xpath(results_xpath)
41+ if not results_dom:
42+ return []
43+
44+ for result_dom in results_dom:
45+ url = extract_text(result_dom.xpath(url_xpath))
46+ title = extract_text(result_dom.xpath(title_xpath))
47+ content = extract_text(result_dom.xpath(content_xpath))
48+ price = extract_text(result_dom.xpath(price_xpath))
49+ shipping = extract_text(result_dom.xpath(shipping_xpath))
50+ source_country = extract_text(result_dom.xpath(source_country_xpath))
51+ thumbnail = extract_text(result_dom.xpath(thumbnail_xpath))
52+
53+ if title == "":
54+ continue
55+
56+ results.append({
57+ 'url': url,
58+ 'title': title,
59+ 'content': content,
60+ 'price': price,
61+ 'shipping': shipping,
62+ 'source_country': source_country,
63+ 'thumbnail': thumbnail,
64+ 'template': 'products.html',
65+
66+ })
67+
68+ return results
searx/settings.yml+6
@@ -235,6 +235,12 @@ engines:
235235 shortcut : et
236236 disabled : True
237237
238+# - name : ebay
239+# engine : ebay
240+# shortcut : eb
241+# disabled : True
242+# timeout: 5
243+
238244 - name : 1x
239245 engine : www1x
240246 shortcut : 1x
searx/templates/oscar/result_templates/products.htmlnew file+22
@@ -0,0 +1,22 @@
1+{% from 'oscar/macros.html' import draw_favicon, result_header, result_sub_header, result_footer_rtl, result_footer %}
2+
3+{{ result_header(result, favicons) }}
4+{{ result_sub_header(result) }}
5+
6+<div class="container-fluid">
7+ <div class="row">
8+ <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>
9+ <p class="col-xs-12 col-sm-9 col-md-9 result-content">
10+ {% if result.price %}<big>{{ result.price|safe }}</big></br>{% endif %}
11+ {% if result.shipping %}<small>{{ result.shipping|safe }}</small></br>{% endif %}
12+ {% if result.source_country %}<small>{{ result.source_country|safe }}</small></br>{% endif %}
13+ {% if result.content %}{{ result.content|safe }}{% endif %}
14+ </p>
15+ </div>
16+</div>
17+
18+{% if rtl %}
19+{{ result_footer_rtl(result) }}
20+{% else %}
21+{{ result_footer(result) }}
22+{% endif %}