generalfile.py 1.4 KB

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