.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
ebay.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3 Ebay (Videos, Music, Files)
4"""
5
6from urllib.parse import quote
7
8from lxml import html
9from searx.engines.xpath import extract_text
10
11# about
12about = {
13 "website": 'https://www.ebay.com',
14 "wikidata_id": 'Q58024',
15 "official_api_documentation": 'https://developer.ebay.com/',
16 "use_official_api": False,
17 "require_api_key": False,
18 "results": 'HTML',
19}
20
21categories = ['shopping']
22paging = True
23
24# Set base_url in settings.yml in order to
25# have the desired local TLD.
26base_url = None
27search_url = '/sch/i.html?_nkw={query}&_sacat={pageno}'
28
29results_xpath = '//li[contains(@class, "s-item")]'
30url_xpath = './/a[@class="s-item__link"]/@href'
31title_xpath = './/h3[@class="s-item__title"]'
32content_xpath = './/div[@span="SECONDARY_INFO"]'
33price_xpath = './/div[contains(@class, "s-item__detail")]/span[@class="s-item__price"][1]/text()'
34shipping_xpath = './/span[contains(@class, "s-item__shipping")]/text()'
35source_country_xpath = './/span[contains(@class, "s-item__location")]/text()'
36thumbnail_xpath = './/img[@class="s-item__image-img"]/@src'
37
38
39def request(query, params):
40 params['url'] = f'{base_url}' + search_url.format(query=quote(query), pageno=params['pageno'])
41 return params
42
43
44def response(resp):
45 results = []
46
47 dom = html.fromstring(resp.text)
48 results_dom = dom.xpath(results_xpath)
49 if not results_dom:
50 return []
51
52 for result_dom in results_dom:
53 url = extract_text(result_dom.xpath(url_xpath))
54 title = extract_text(result_dom.xpath(title_xpath))
55 content = extract_text(result_dom.xpath(content_xpath))
56 price = extract_text(result_dom.xpath(price_xpath))
57 shipping = extract_text(result_dom.xpath(shipping_xpath))
58 source_country = extract_text(result_dom.xpath(source_country_xpath))
59 thumbnail = extract_text(result_dom.xpath(thumbnail_xpath))
60
61 if title == "":
62 continue
63
64 results.append(
65 {
66 'url': url,
67 'title': title,
68 'content': content,
69 'price': price,
70 'shipping': shipping,
71 'source_country': source_country,
72 'thumbnail': thumbnail,
73 'template': 'products.html',
74 }
75 )
76
77 return results
request(query, params)
Definition ebay.py:39
response(resp)
Definition ebay.py:44