1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/searx_ynh.git synced 2024-09-03 20:16:30 +02:00
searx_ynh/sources/searx/engines/flickr.py

55 lines
1.5 KiB
Python
Raw Normal View History

2014-05-10 11:56:19 +02:00
#!/usr/bin/env python
from urllib import urlencode
2014-05-27 12:13:54 +02:00
#from json import loads
2014-05-10 11:56:19 +02:00
from urlparse import urljoin
2014-05-27 12:13:54 +02:00
from lxml import html
from time import time
2014-05-10 11:56:19 +02:00
categories = ['images']
url = 'https://secure.flickr.com/'
search_url = url+'search/?{query}&page={page}'
2014-05-27 12:13:54 +02:00
results_xpath = '//div[@class="view display-item-tile"]/figure/div'
2014-05-10 11:56:19 +02:00
paging = True
def request(query, params):
2014-05-27 12:13:54 +02:00
params['url'] = search_url.format(query=urlencode({'text': query}),
2014-05-10 11:56:19 +02:00
page=params['pageno'])
2014-05-27 12:13:54 +02:00
time_string = str(int(time())-3)
params['cookies']['BX'] = '3oqjr6d9nmpgl&b=3&s=dh'
params['cookies']['xb'] = '421409'
params['cookies']['localization'] = 'en-us'
params['cookies']['flrbp'] = time_string +\
'-3a8cdb85a427a33efda421fbda347b2eaf765a54'
params['cookies']['flrbs'] = time_string +\
'-ed142ae8765ee62c9ec92a9513665e0ee1ba6776'
params['cookies']['flrb'] = '9'
2014-05-10 11:56:19 +02:00
return params
def response(resp):
results = []
dom = html.fromstring(resp.text)
for result in dom.xpath(results_xpath):
2014-05-27 12:13:54 +02:00
img = result.xpath('.//img')
if not img:
continue
img = img[0]
img_src = 'https:'+img.attrib.get('src')
2014-05-10 11:56:19 +02:00
if not img_src:
continue
2014-05-27 12:13:54 +02:00
href = urljoin(url, result.xpath('.//a')[0].attrib.get('href'))
title = img.attrib.get('alt', '')
2014-05-10 11:56:19 +02:00
results.append({'url': href,
'title': title,
'img_src': img_src,
'template': 'images.html'})
return results