Ponysearch/searx/engines/flickr.py

29 lines
908 B
Python
Raw Normal View History

2013-10-18 02:15:26 +02:00
#!/usr/bin/env python
from urllib import quote
from lxml import html
from urlparse import urljoin
2013-10-18 09:35:29 +02:00
categories = ['images']
2013-10-18 02:15:26 +02:00
base_url = 'https://secure.flickr.com/'
search_url = base_url+'search/?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)
2013-10-18 09:35:29 +02:00
for result in dom.xpath('//div[@id="thumbnails"]//a[@class="rapidnofollow photo-click" and @data-track="photo-click"]'):
2013-10-18 02:15:26 +02:00
url = urljoin(base_url, result.attrib.get('href'))
2013-10-18 09:35:29 +02:00
img = result.xpath('.//img')[0]
title = img.attrib.get('alt', '')
content = '<img src="%s" alt="%s" />' % (img.attrib.get('data-defer-src', ''), title)
2013-10-18 02:15:26 +02:00
results.append({'url': url, 'title': title, 'content': content})
return results