| 
									
										
										
										
											2021-01-13 11:31:25 +01:00
										 |  |  | # SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							|  |  |  | """
 | 
					
						
							|  |  |  |  Ebay (Videos, Music, Files) | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2018-02-09 23:52:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | from lxml import html | 
					
						
							|  |  |  | from searx.engines.xpath import extract_text | 
					
						
							|  |  |  | from urllib.parse import quote | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-13 11:31:25 +01:00
										 |  |  | # about | 
					
						
							|  |  |  | about = { | 
					
						
							|  |  |  |     "website": 'https://www.ebay.com', | 
					
						
							|  |  |  |     "wikidata_id": 'Q58024', | 
					
						
							|  |  |  |     "official_api_documentation": 'https://developer.ebay.com/', | 
					
						
							|  |  |  |     "use_official_api": False, | 
					
						
							|  |  |  |     "require_api_key": False, | 
					
						
							|  |  |  |     "results": 'HTML', | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-09 23:52:11 +01:00
										 |  |  | categories = ['shopping'] | 
					
						
							|  |  |  | paging = True | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | url = 'https://www.ebay.com' | 
					
						
							|  |  |  | search_url = url + '/sch/i.html?_nkw={query}&_sacat={pageno}' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | results_xpath = '//li[contains(@class, "s-item")]' | 
					
						
							|  |  |  | url_xpath = './/a[@class="s-item__link"]/@href' | 
					
						
							|  |  |  | title_xpath = './/h3[@class="s-item__title"]' | 
					
						
							|  |  |  | content_xpath = './/div[@span="SECONDARY_INFO"]' | 
					
						
							|  |  |  | price_xpath = './/div[contains(@class, "s-item__detail")]/span[@class="s-item__price"][1]/text()' | 
					
						
							|  |  |  | shipping_xpath = './/span[contains(@class, "s-item__shipping")]/text()' | 
					
						
							|  |  |  | source_country_xpath = './/span[contains(@class, "s-item__location")]/text()' | 
					
						
							|  |  |  | thumbnail_xpath = './/img[@class="s-item__image-img"]/@src' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def request(query, params): | 
					
						
							|  |  |  |     params['url'] = search_url.format(query=quote(query), pageno=params['pageno']) | 
					
						
							|  |  |  |     return params | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def response(resp): | 
					
						
							|  |  |  |     results = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dom = html.fromstring(resp.text) | 
					
						
							|  |  |  |     results_dom = dom.xpath(results_xpath) | 
					
						
							|  |  |  |     if not results_dom: | 
					
						
							|  |  |  |         return [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for result_dom in results_dom: | 
					
						
							|  |  |  |         url = extract_text(result_dom.xpath(url_xpath)) | 
					
						
							|  |  |  |         title = extract_text(result_dom.xpath(title_xpath)) | 
					
						
							|  |  |  |         content = extract_text(result_dom.xpath(content_xpath)) | 
					
						
							|  |  |  |         price = extract_text(result_dom.xpath(price_xpath)) | 
					
						
							|  |  |  |         shipping = extract_text(result_dom.xpath(shipping_xpath)) | 
					
						
							|  |  |  |         source_country = extract_text(result_dom.xpath(source_country_xpath)) | 
					
						
							|  |  |  |         thumbnail = extract_text(result_dom.xpath(thumbnail_xpath)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if title == "": | 
					
						
							|  |  |  |             continue | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-27 09:26:22 +01:00
										 |  |  |         results.append( | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 'url': url, | 
					
						
							|  |  |  |                 'title': title, | 
					
						
							|  |  |  |                 'content': content, | 
					
						
							|  |  |  |                 'price': price, | 
					
						
							|  |  |  |                 'shipping': shipping, | 
					
						
							|  |  |  |                 'source_country': source_country, | 
					
						
							|  |  |  |                 'thumbnail': thumbnail, | 
					
						
							|  |  |  |                 'template': 'products.html', | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2018-02-09 23:52:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return results |