summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorAdam Tauber <asciimoo@gmail.com>2013-10-19 13:36:55 -0700
committerAdam Tauber <asciimoo@gmail.com>2013-10-19 13:36:55 -0700
commit225c7ecbcf52cca223dd40267274924de0995880 (patch)
treec05c08a702792ef6c8e50d3b66dea9960c367811 /searx/engines
parenta0cbc767e7bb67deabda7a75f6ba5389143b86a0 (diff)
parente31a234551e2ced9551158cc5ac5d391b14e994e (diff)
downloadsearxng-225c7ecbcf52cca223dd40267274924de0995880.tar.gz
searxng-225c7ecbcf52cca223dd40267274924de0995880.zip
Merge pull request #2 from stef/master
google images engine
Diffstat (limited to 'searx/engines')
-rwxr-xr-xsearx/engines/gimages.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/searx/engines/gimages.py b/searx/engines/gimages.py
new file mode 100755
index 000000000..9e75bff0c
--- /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 = ['images']
+
+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 = '<img src="%s" alt="%s" />' % (img.attrib.get('src', ''), title)
+ results.append({'url': url, 'title': title, 'content': content})
+ return results