searxng/searx/engines/generalfile.py

63 lines
1.4 KiB
Python
Raw Normal View History

"""
General Files (Files)
@website http://www.general-files.org
@provide-api no (nothing found)
@using-api no (because nothing found)
@results HTML (using search portal)
@stable no (HTML can change)
@parse url, title, content
@todo detect torrents?
"""
2014-06-27 15:25:16 +00:00
from lxml import html
# engine dependent config
categories = ['files']
paging = True
2014-06-27 15:25:16 +00:00
# search-url
2014-06-27 15:25:16 +00:00
base_url = 'http://www.general-file.com'
search_url = base_url + '/files-{letter}/{query}/{pageno}'
# specific xpath variables
2014-06-27 15:25:16 +00:00
result_xpath = '//table[@class="block-file"]'
title_xpath = './/h2/a//text()'
url_xpath = './/h2/a/@href'
content_xpath = './/p//text()'
# do search-request
2014-06-27 15:25:16 +00:00
def request(query, params):
2014-06-27 15:25:16 +00:00
params['url'] = search_url.format(query=query,
letter=query[0],
pageno=params['pageno'])
2014-06-27 15:25:16 +00:00
return params
# get response from search-request
2014-06-27 15:25:16 +00:00
def response(resp):
results = []
2014-06-27 15:25:16 +00:00
dom = html.fromstring(resp.text)
# parse results
2014-06-27 15:25:16 +00:00
for result in dom.xpath(result_xpath):
url = result.xpath(url_xpath)[0]
2014-06-27 15:25:16 +00:00
# skip fast download links
if not url.startswith('/'):
continue
# append result
2014-06-27 15:25:16 +00:00
results.append({'url': base_url + url,
'title': ''.join(result.xpath(title_xpath)),
'content': ''.join(result.xpath(content_xpath))})
# return results
2014-06-27 15:25:16 +00:00
return results