generalfile.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ## General Files (Files)
  2. #
  3. # @website http://www.general-files.org
  4. # @provide-api no (nothing found)
  5. #
  6. # @using-api no (because nothing found)
  7. # @results HTML (using search portal)
  8. # @stable no (HTML can change)
  9. # @parse url, title, content
  10. #
  11. # @todo detect torrents?
  12. from lxml import html
  13. # engine dependent config
  14. categories = ['files']
  15. paging = True
  16. # search-url
  17. base_url = 'http://www.general-file.com'
  18. search_url = base_url + '/files-{letter}/{query}/{pageno}'
  19. # specific xpath variables
  20. result_xpath = '//table[@class="block-file"]'
  21. title_xpath = './/h2/a//text()'
  22. url_xpath = './/h2/a/@href'
  23. content_xpath = './/p//text()'
  24. # do search-request
  25. def request(query, params):
  26. params['url'] = search_url.format(query=query,
  27. letter=query[0],
  28. pageno=params['pageno'])
  29. return params
  30. # get response from search-request
  31. def response(resp):
  32. results = []
  33. dom = html.fromstring(resp.text)
  34. # parse results
  35. for result in dom.xpath(result_xpath):
  36. url = result.xpath(url_xpath)[0]
  37. # skip fast download links
  38. if not url.startswith('/'):
  39. continue
  40. # append result
  41. results.append({'url': base_url + url,
  42. 'title': ''.join(result.xpath(title_xpath)),
  43. 'content': ''.join(result.xpath(content_xpath))})
  44. # return results
  45. return results