logo

searx

Unnamed repository; edit this file 'description' to name the repository.
commit: 1ba2762b674fd08a67bf9460b03081892359af24
parent: 23b327c6ae47c4b9bc9f00f95b19201b37d237d6
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Wed,  8 Jan 2014 03:05:57 -0800

Merge pull request #17 from pw3t/vimeo

Vimeo engine added

Diffstat:

engines.cfg_sample | 7+++++++
searx/engines/vimeo.py | 38++++++++++++++++++++++++++++++++++++++
searx/webapp.py | 2+-
3 files changed, 46 insertions(+), 1 deletion(-)

diff --git a/engines.cfg_sample b/engines.cfg_sample @@ -86,3 +86,10 @@ engine = dailymotion locale = en_US categories = videos +[vimeo] +engine = vimeo +categories = videos +results_xpath = //div[@id="browse_content"]/ol/li +url_xpath=./a/@href +title_xpath=./a/div[@class="data"]/p[@class="title"]/text() +content_xpath=./a/img/@src diff --git a/searx/engines/vimeo.py b/searx/engines/vimeo.py @@ -0,0 +1,38 @@ +from urllib import urlencode +from HTMLParser import HTMLParser +from xpath import extract_text +from lxml import html + +base_url = 'http://vimeo.com' +search_url = base_url + '/search?{query}' + +# the cookie set by vime contains all the following values, but only __utma seems to be requiered +Cookie = { + #'vuid':'918282893.1027205400' + # 'ab_bs':'%7B%223%22%3A279%7D' + '__utma':'00000000.000#0000000.0000000000.0000000000.0000000000.0' + # '__utmb':'18302654.1.10.1388942090' + #, '__utmc':'18302654' + #, '__utmz':'18#302654.1388942090.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)' + #, '__utml':'search' +} + +def request(query, params): + params['url'] = search_url.format(query=urlencode({'q' :query})) + print params['url'] + params['cookies'] = Cookie + return params + +def response(resp): + results = [] + dom = html.fromstring(resp.text) + + p = HTMLParser() + + for result in dom.xpath(results_xpath): + url = base_url + result.xpath(url_xpath)[0] + title = p.unescape(extract_text(result.xpath(title_xpath))) + content = '<a href="{0}"> <img src="{2}"/> </a>'.format(url, title, extract_text(result.xpath(content_xpath)[0])) + results.append({'url': url, 'title': title, 'content': content}) + + return results diff --git a/searx/webapp.py b/searx/webapp.py @@ -107,7 +107,7 @@ def index(): if len(result['url']) > 74: result['pretty_url'] = result['url'][:35] + '[..]' + result['url'][-35:] else: - result['pretty_url'] = result['url'] + result['pretty_url'] = result['url'] if request_data.get('format') == 'json': return Response(json.dumps({'query': query, 'results': results}), mimetype='application/json')