www1x.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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
  9. """
  10. from lxml import html, etree
  11. from urllib.parse import urlencode, urljoin
  12. from searx.utils import extract_text, eval_xpath_list, eval_xpath_getindex
  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. gallery_url = 'https://gallery.1x.com/'
  20. # do search-request
  21. def request(query, params):
  22. params['url'] = search_url.format(query=urlencode({'q': query}))
  23. return params
  24. # get response from search-request
  25. def response(resp):
  26. results = []
  27. xmldom = etree.fromstring(resp.content)
  28. xmlsearchresult = eval_xpath_getindex(xmldom, '//searchresult', 0)
  29. dom = html.fragment_fromstring(xmlsearchresult.text, create_parent='div')
  30. for link in eval_xpath_list(dom, '/div/table/tr/td/div[2]//a'):
  31. url = urljoin(base_url, link.attrib.get('href'))
  32. title = extract_text(link)
  33. thumbnail_src = urljoin(gallery_url, eval_xpath_getindex(link, './/img', 0).attrib['src'])
  34. # append result
  35. results.append({'url': url,
  36. 'title': title,
  37. 'img_src': thumbnail_src,
  38. 'content': '',
  39. 'thumbnail_src': thumbnail_src,
  40. 'template': 'images.html'})
  41. # return results
  42. return results