From 7c11c7056fdbc2e72126583e33f35985557773c6 Mon Sep 17 00:00:00 2001 From: stef Date: Sat, 19 Oct 2013 22:19:14 +0200 Subject: [PATCH 1/2] [enh] added google images engine --- searx/engines/gimages.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 searx/engines/gimages.py diff --git a/searx/engines/gimages.py b/searx/engines/gimages.py new file mode 100755 index 000000000..941e0fe4f --- /dev/null +++ b/searx/engines/gimages.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +from urllib import quote +from lxml import html +from urlparse import urljoin + +categories = ['test'] + +base_url = 'https://www.google.com/' +search_url = base_url+'search?tbm=isch&hl=en&q=' + +def request(query, params): + global search_url + query = quote(query.replace(' ', '+'), safe='+') + params['url'] = search_url + query + return params + +def response(resp): + global base_url + results = [] + dom = html.fromstring(resp.text) + for result in dom.xpath('//table[@class="images_table"]//a'): + url = urljoin(base_url, result.attrib.get('href')) + img = result.xpath('.//img')[0] + title = ' '.join(result.xpath('..//text()')) + content = '%s' % (img.attrib.get('src', ''), title) + results.append({'url': url, 'title': title, 'content': content}) + return results From b305af45418d5b4e1f7060a24d1eb3e2ec2e405d Mon Sep 17 00:00:00 2001 From: stef Date: Sat, 19 Oct 2013 22:19:31 +0200 Subject: [PATCH 2/2] [mod] category -> images --- searx/engines/gimages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searx/engines/gimages.py b/searx/engines/gimages.py index 941e0fe4f..9e75bff0c 100755 --- a/searx/engines/gimages.py +++ b/searx/engines/gimages.py @@ -4,7 +4,7 @@ from urllib import quote from lxml import html from urlparse import urljoin -categories = ['test'] +categories = ['images'] base_url = 'https://www.google.com/' search_url = base_url+'search?tbm=isch&hl=en&q='