Sfoglia il codice sorgente

Merge 8f1fb9ae9fbfde3be4694087fe4f6258aadf81b4 into f82ead3e303d75ba63a370dc038311e172e1330d

Noémi Ványi 6 anni fa
parent
commit
4fa274ec48
No account linked to committer's email

+ 65
- 0
searx/engines/ebay.py Vedi File

@@ -0,0 +1,65 @@
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 searx.url_utils 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}&_pgn={pageno}'
20
+
21
+results_xpath = '//li[contains(@class, "lvresult")]'
22
+url_xpath = './h3[@class="lvtitle"]/a/@href'
23
+title_xpath = './h3[@class="lvtitle"]/a/text()'
24
+content_xpath = './div[@class="lvsubtitle"]/text()'
25
+price_xpath = './ul[@class="lvprices left space-zero"]/li[@class="lvprice prc"][1]/span[@class="bold"]'
26
+shipping_xpath = './ul[@class="lvprices left space-zero"]/li[@class="lvshipping"]/span[@class="ship"]/span/span/text()'
27
+source_country_xpath = './ul[contains(@class, "lvdetails")]/li[1]'
28
+thumbnail_xpath = './div[contains(@class, "lvpic")]//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
+        results.append({
54
+            'url': url, 
55
+            'title': title, 
56
+            'content': content, 
57
+            'price': price, 
58
+            'shipping': shipping, 
59
+            'source_country': source_country, 
60
+            'thumbnail': thumbnail, 
61
+            'template': 'products.html',
62
+
63
+        })
64
+
65
+    return results

+ 6
- 0
searx/settings.yml Vedi File

@@ -200,6 +200,12 @@ engines:
200 200
     shortcut : et
201 201
     disabled : True
202 202
 
203
+  - name : ebay
204
+    engine : ebay
205
+    shortcut : eb
206
+    disabled : True
207
+    timeout: 5
208
+
203 209
   - name : faroo
204 210
     engine : faroo
205 211
     shortcut : fa

+ 22
- 0
searx/templates/oscar/result_templates/products.html Vedi File

@@ -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 %}