ebay.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. Ebay (Videos, Music, Files)
  4. """
  5. from lxml import html
  6. from searx.engines.xpath import extract_text
  7. from urllib.parse import quote
  8. # about
  9. about = {
  10. "website": 'https://www.ebay.com',
  11. "wikidata_id": 'Q58024',
  12. "official_api_documentation": 'https://developer.ebay.com/',
  13. "use_official_api": False,
  14. "require_api_key": False,
  15. "results": 'HTML',
  16. }
  17. categories = ['shopping']
  18. paging = True
  19. url = 'https://www.ebay.com'
  20. search_url = url + '/sch/i.html?_nkw={query}&_sacat={pageno}'
  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. def request(query, params):
  30. params['url'] = search_url.format(query=quote(query), pageno=params['pageno'])
  31. return params
  32. def response(resp):
  33. results = []
  34. dom = html.fromstring(resp.text)
  35. results_dom = dom.xpath(results_xpath)
  36. if not results_dom:
  37. return []
  38. for result_dom in results_dom:
  39. url = extract_text(result_dom.xpath(url_xpath))
  40. title = extract_text(result_dom.xpath(title_xpath))
  41. content = extract_text(result_dom.xpath(content_xpath))
  42. price = extract_text(result_dom.xpath(price_xpath))
  43. shipping = extract_text(result_dom.xpath(shipping_xpath))
  44. source_country = extract_text(result_dom.xpath(source_country_xpath))
  45. thumbnail = extract_text(result_dom.xpath(thumbnail_xpath))
  46. if title == "":
  47. continue
  48. results.append({
  49. 'url': url,
  50. 'title': title,
  51. 'content': content,
  52. 'price': price,
  53. 'shipping': shipping,
  54. 'source_country': source_country,
  55. 'thumbnail': thumbnail,
  56. 'template': 'products.html',
  57. })
  58. return results