generalfile.py 957 B

1234567891011121314151617181920212223242526272829303132333435
  1. from lxml import html
  2. base_url = 'http://www.general-file.com'
  3. search_url = base_url + '/files-{letter}/{query}/{pageno}'
  4. result_xpath = '//table[@class="block-file"]'
  5. title_xpath = './/h2/a//text()'
  6. url_xpath = './/h2/a/@href'
  7. content_xpath = './/p//text()'
  8. paging = True
  9. def request(query, params):
  10. params['url'] = search_url.format(query=query,
  11. letter=query[0],
  12. pageno=params['pageno'])
  13. return params
  14. def response(resp):
  15. results = []
  16. dom = html.fromstring(resp.text)
  17. for result in dom.xpath(result_xpath):
  18. url = result.xpath(url_xpath)[0]
  19. # skip fast download links
  20. if not url.startswith('/'):
  21. continue
  22. results.append({'url': base_url + url,
  23. 'title': ''.join(result.xpath(title_xpath)),
  24. 'content': ''.join(result.xpath(content_xpath))})
  25. return results