Procházet zdrojové kódy

add ebay enginte to shopping category

Noémi Ványi před 6 roky
rodič
revize
f9a07f9071
2 změnil soubory, kde provedl 71 přidání a 0 odebrání
  1. 65
    0
      searx/engines/ebay.py
  2. 6
    0
      searx/settings.yml

+ 65
- 0
searx/engines/ebay.py Zobrazit soubor

@@ -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 Zobrazit soubor

@@ -195,6 +195,12 @@ engines:
195 195
     shortcut : et
196 196
     disabled : True
197 197
 
198
+  - name : ebay
199
+    engine : ebay
200
+    shortcut : eb
201
+    disabled : True
202
+    timeout: 5
203
+
198 204
   - name : faroo
199 205
     engine : faroo
200 206
     shortcut : fa