logo

searx

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

framalibre.py (2032B)


  1. """
  2. FramaLibre (It)
  3. @website https://framalibre.org/
  4. @provide-api no
  5. @using-api no
  6. @results HTML
  7. @stable no (HTML can change)
  8. @parse url, title, content, thumbnail, img_src
  9. """
  10. from cgi import escape
  11. from lxml import html
  12. from searx.engines.xpath import extract_text
  13. from searx.url_utils import urljoin, urlencode
  14. # engine dependent config
  15. categories = ['it']
  16. paging = True
  17. # search-url
  18. base_url = 'https://framalibre.org/'
  19. search_url = base_url + 'recherche-par-crit-res?{query}&page={offset}'
  20. # specific xpath variables
  21. results_xpath = '//div[@class="nodes-list-row"]/div[contains(@typeof,"sioc:Item")]'
  22. link_xpath = './/h3[@class="node-title"]/a[@href]'
  23. thumbnail_xpath = './/img[@class="media-object img-responsive"]/@src'
  24. content_xpath = './/div[@class="content"]//p'
  25. # do search-request
  26. def request(query, params):
  27. offset = (params['pageno'] - 1)
  28. params['url'] = search_url.format(query=urlencode({'keys': query}),
  29. offset=offset)
  30. return params
  31. # get response from search-request
  32. def response(resp):
  33. results = []
  34. dom = html.fromstring(resp.text)
  35. # parse results
  36. for result in dom.xpath(results_xpath):
  37. link = result.xpath(link_xpath)[0]
  38. href = urljoin(base_url, link.attrib.get('href'))
  39. # there's also a span (class="rdf-meta element-hidden" property="dc:title")'s content property for this...
  40. title = escape(extract_text(link))
  41. thumbnail_tags = result.xpath(thumbnail_xpath)
  42. thumbnail = None
  43. if len(thumbnail_tags) > 0:
  44. thumbnail = extract_text(thumbnail_tags[0])
  45. if thumbnail[0] == '/':
  46. thumbnail = base_url + thumbnail
  47. content = escape(extract_text(result.xpath(content_xpath)))
  48. # append result
  49. results.append({'url': href,
  50. 'title': title,
  51. 'img_src': thumbnail,
  52. 'content': content})
  53. # return results
  54. return results