www1x.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. 1x (Images)
  3. @website http://1x.com/
  4. @provide-api no
  5. @using-api no
  6. @results HTML
  7. @stable no (HTML can change)
  8. @parse url, title, thumbnail, img_src, content
  9. """
  10. from lxml import html
  11. from searx.url_utils import urlencode, urljoin
  12. from searx.engines.xpath import extract_text
  13. # engine dependent config
  14. categories = ['images']
  15. paging = False
  16. # search-url
  17. base_url = 'https://1x.com'
  18. search_url = base_url + '/backend/search.php?{query}'
  19. # do search-request
  20. def request(query, params):
  21. params['url'] = search_url.format(query=urlencode({'q': query}))
  22. return params
  23. # get response from search-request
  24. def response(resp):
  25. results = []
  26. dom = html.fromstring(resp.text)
  27. for res in dom.xpath('//div[@class="List-item MainListing"]'):
  28. # processed start and end of link
  29. link = res.xpath('//a')[0]
  30. url = urljoin(base_url, link.attrib.get('href'))
  31. title = extract_text(link)
  32. thumbnail_src = urljoin(base_url, res.xpath('.//img')[0].attrib['src'])
  33. # TODO: get image with higher resolution
  34. img_src = thumbnail_src
  35. # append result
  36. results.append({'url': url,
  37. 'title': title,
  38. 'img_src': img_src,
  39. 'content': '',
  40. 'thumbnail_src': thumbnail_src,
  41. 'template': 'images.html'})
  42. # return results
  43. return results