searxng/searx/engines/google_images.py

29 lines
929 B
Python
Raw Normal View History

2013-10-19 20:19:14 +00:00
#!/usr/bin/env python
2013-10-19 21:12:18 +00:00
from urllib import urlencode
from json import loads
2013-10-19 20:19:14 +00:00
2013-10-19 20:19:31 +00:00
categories = ['images']
2013-10-19 20:19:14 +00:00
2013-10-19 21:12:18 +00:00
search_url = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&start=0&rsz=large&safe=off&filter=off&'
2013-10-19 20:19:14 +00:00
def request(query, params):
global search_url
2013-10-19 21:12:18 +00:00
params['url'] = search_url + urlencode({'q': query})
2013-10-19 20:19:14 +00:00
return params
def response(resp):
global base_url
results = []
2013-10-19 21:12:18 +00:00
search_res = loads(resp.text)
if 'responseData' not in search_res:
return []
for result in search_res['responseData']['results']:
url = result['originalContextUrl']
title = result['title']
2013-10-19 21:18:39 +00:00
content = '<a href="%s"><img src="%s" title="%s" style="max-width: 500px; "/></a>' % (result['url'], result['url'], title)
if result['content']:
content += '<br />'+result['content']
2013-10-19 20:19:14 +00:00
results.append({'url': url, 'title': title, 'content': content})
return results