| 
									
										
										
										
											2015-05-02 15:45:17 +02:00
										 |  |  | """
 | 
					
						
							|  |  |  |  1x (Images) | 
					
						
							| 
									
										
										
										
											2015-02-01 11:27:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-02 15:45:17 +02:00
										 |  |  |  @website     http://1x.com/ | 
					
						
							|  |  |  |  @provide-api no | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  @using-api   no | 
					
						
							|  |  |  |  @results     HTML | 
					
						
							|  |  |  |  @stable      no (HTML can change) | 
					
						
							|  |  |  |  @parse       url, title, thumbnail, img_src, content | 
					
						
							|  |  |  | """
 | 
					
						
							| 
									
										
										
										
											2015-02-01 11:27:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | from lxml import html | 
					
						
							| 
									
										
										
										
											2016-11-30 18:43:03 +01:00
										 |  |  | from searx.url_utils import urlencode, urljoin | 
					
						
							| 
									
										
										
										
											2019-10-16 13:27:05 +02:00
										 |  |  | from searx.engines.xpath import extract_text | 
					
						
							| 
									
										
										
										
											2015-02-01 11:27:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # engine dependent config | 
					
						
							|  |  |  | categories = ['images'] | 
					
						
							|  |  |  | paging = False | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-06-06 19:44:41 +02:00
										 |  |  | # search-url | 
					
						
							| 
									
										
										
										
											2015-06-06 19:23:07 +02:00
										 |  |  | base_url = 'https://1x.com' | 
					
						
							| 
									
										
										
										
											2016-01-18 12:47:31 +01:00
										 |  |  | search_url = base_url + '/backend/search.php?{query}' | 
					
						
							| 
									
										
										
										
											2015-02-01 11:27:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # do search-request | 
					
						
							|  |  |  | def request(query, params): | 
					
						
							|  |  |  |     params['url'] = search_url.format(query=urlencode({'q': query})) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return params | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # get response from search-request | 
					
						
							|  |  |  | def response(resp): | 
					
						
							|  |  |  |     results = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 13:27:05 +02:00
										 |  |  |     dom = html.fromstring(resp.text) | 
					
						
							|  |  |  |     for res in dom.xpath('//div[@class="List-item MainListing"]'): | 
					
						
							| 
									
										
										
										
											2015-02-01 11:27:28 +01:00
										 |  |  |         # processed start and end of link | 
					
						
							| 
									
										
										
										
											2019-10-16 13:27:05 +02:00
										 |  |  |         link = res.xpath('//a')[0] | 
					
						
							| 
									
										
										
										
											2015-02-01 11:27:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         url = urljoin(base_url, link.attrib.get('href')) | 
					
						
							| 
									
										
										
										
											2019-10-16 13:27:05 +02:00
										 |  |  |         title = extract_text(link) | 
					
						
							| 
									
										
										
										
											2015-02-01 11:27:28 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-16 13:27:05 +02:00
										 |  |  |         thumbnail_src = urljoin(base_url, res.xpath('.//img')[0].attrib['src']) | 
					
						
							| 
									
										
										
										
											2015-02-01 11:27:28 +01:00
										 |  |  |         # TODO: get image with higher resolution | 
					
						
							|  |  |  |         img_src = thumbnail_src | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # append result | 
					
						
							|  |  |  |         results.append({'url': url, | 
					
						
							|  |  |  |                         'title': title, | 
					
						
							|  |  |  |                         'img_src': img_src, | 
					
						
							|  |  |  |                         'content': '', | 
					
						
							|  |  |  |                         'thumbnail_src': thumbnail_src, | 
					
						
							|  |  |  |                         'template': 'images.html'}) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # return results | 
					
						
							|  |  |  |     return results |