diff options
author | François Revol <revol@free.fr> | 2017-01-06 00:22:43 +0100 |
---|---|---|
committer | François Revol <revol@free.fr> | 2017-03-22 00:18:23 +0100 |
commit | 45d15bd6f0d64c9e10dde31cec239936ee553dd6 (patch) | |
tree | 1520ef54b1563b7417ae86e0f61444faa4c0557e /searx/engines | |
parent | ddd5c2632ff92947d80e530e93ba65c62537a298 (diff) | |
download | searxng-45d15bd6f0d64c9e10dde31cec239936ee553dd6.tar.gz searxng-45d15bd6f0d64c9e10dde31cec239936ee553dd6.zip |
Add framalibre engine
framalibre.org is a catalogue of Free Software, edited by Framasoft.
For now we pass the thumbnail as img_src as it doesn't seem to be used
for IT...
Diffstat (limited to 'searx/engines')
-rw-r--r-- | searx/engines/framalibre.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/searx/engines/framalibre.py b/searx/engines/framalibre.py new file mode 100644 index 000000000..e8d1d8aa7 --- /dev/null +++ b/searx/engines/framalibre.py @@ -0,0 +1,72 @@ +""" + FramaLibre (It) + + @website https://framalibre.org/ + @provide-api no + + @using-api no + @results HTML + @stable no (HTML can change) + @parse url, title, content, thumbnail, img_src +""" + +from urlparse import urljoin +from cgi import escape +from urllib import urlencode +from lxml import html +from searx.engines.xpath import extract_text +from dateutil import parser + +# engine dependent config +categories = ['it'] +paging = True + +# search-url +base_url = 'https://framalibre.org/' +search_url = base_url + 'recherche-par-crit-res?{query}&page={offset}' + +# specific xpath variables +results_xpath = '//div[@class="nodes-list-row"]/div[contains(@typeof,"sioc:Item")]' +link_xpath = './/h3[@class="node-title"]/a[@href]' +thumbnail_xpath = './/img[@class="media-object img-responsive"]/@src' +content_xpath = './/div[@class="content"]//p' + + +# do search-request +def request(query, params): + offset = (params['pageno'] - 1) + params['url'] = search_url.format(query=urlencode({'keys': query}), + offset=offset) + + return params + + +# get response from search-request +def response(resp): + results = [] + + dom = html.fromstring(resp.text) + + # parse results + for result in dom.xpath(results_xpath): + link = result.xpath(link_xpath)[0] + href = urljoin(base_url, link.attrib.get('href')) + # there's also a span (class="rdf-meta element-hidden" property="dc:title")'s content property for this... + title = escape(extract_text(link)) + thumbnail_tags = result.xpath(thumbnail_xpath) + thumbnail = None + if len(thumbnail_tags) > 0: + thumbnail = extract_text(thumbnail_tags[0]) + if thumbnail[0] == '/': + thumbnail = base_url + thumbnail + content = escape(extract_text(result.xpath(content_xpath))) + + # append result + results.append({'url': href, + 'title': title, + 'thumbnail': thumbnail, + 'img_src': thumbnail, + 'content': content}) + + # return results + return results |