logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://hacktivis.me/git/searx.git

www1x.py (1987B)


  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. import re
  12. from searx.url_utils import urlencode, urljoin
  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. # get links from result-text
  27. regex = re.compile('(</a>|<a)')
  28. results_parts = re.split(regex, resp.text)
  29. cur_element = ''
  30. # iterate over link parts
  31. for result_part in results_parts:
  32. # processed start and end of link
  33. if result_part == '<a':
  34. cur_element = result_part
  35. continue
  36. elif result_part != '</a>':
  37. cur_element += result_part
  38. continue
  39. cur_element += result_part
  40. # fix xml-error
  41. cur_element = cur_element.replace('"></a>', '"/></a>')
  42. dom = html.fromstring(cur_element)
  43. link = dom.xpath('//a')[0]
  44. url = urljoin(base_url, link.attrib.get('href'))
  45. title = link.attrib.get('title', '')
  46. thumbnail_src = urljoin(base_url, link.xpath('.//img')[0].attrib['src'])
  47. # TODO: get image with higher resolution
  48. img_src = thumbnail_src
  49. # check if url is showing to a photo
  50. if '/photo/' not in url:
  51. continue
  52. # append result
  53. results.append({'url': url,
  54. 'title': title,
  55. 'img_src': img_src,
  56. 'content': '',
  57. 'thumbnail_src': thumbnail_src,
  58. 'template': 'images.html'})
  59. # return results
  60. return results