mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
#!/usr/bin/env python
|
|
|
|
from urllib import urlencode
|
|
from lxml import html
|
|
from urlparse import urljoin
|
|
|
|
categories = ['images']
|
|
|
|
#https://secure.flickr.com/search?data=1&q=asdf&s=&page=3&mt=&cm=&m=&l=&w=&hd=&d=&append=1
|
|
|
|
url = 'https://secure.flickr.com/'
|
|
search_url = url+'search/?{query}&page={page}'
|
|
results_xpath = '//div[@id="thumbnails"]//a[@class="rapidnofollow photo-click" and @data-track="photo-click"]' # noqa
|
|
|
|
paging = True
|
|
|
|
|
|
def request(query, params):
|
|
params['url'] = search_url.format(query=urlencode({'q': query}),
|
|
page=params['pageno'])
|
|
return params
|
|
|
|
|
|
def response(resp):
|
|
global base_url
|
|
results = []
|
|
dom = html.fromstring(resp.text)
|
|
for result in dom.xpath(results_xpath):
|
|
href = urljoin(url, result.attrib.get('href'))
|
|
img = result.xpath('.//img')[0]
|
|
title = img.attrib.get('alt', '')
|
|
img_src = img.attrib.get('data-defer-src')
|
|
if not img_src:
|
|
continue
|
|
results.append({'url': href,
|
|
'title': title,
|
|
'img_src': img_src,
|
|
'template': 'images.html'})
|
|
return results
|