1
0
mirror of https://github.com/searxng/searxng.git synced 2024-11-23 12:31:25 +01:00
searxng/searx/engines/flickr.py

55 lines
1.5 KiB
Python
Raw Normal View History

2013-10-18 02:15:26 +02:00
#!/usr/bin/env python
2013-10-23 23:55:37 +02:00
from urllib import urlencode
2014-05-20 16:57:03 +02:00
#from json import loads
from urlparse import urljoin
from lxml import html
from time import time
2013-10-18 02:15:26 +02:00
2013-10-18 09:35:29 +02:00
categories = ['images']
2013-10-18 02:15:26 +02:00
2014-05-20 16:57:03 +02:00
url = 'https://secure.flickr.com/'
search_url = url+'search/?{query}&page={page}'
results_xpath = '//div[@class="view display-item-tile"]/figure/div'
2014-01-20 02:31:20 +01:00
2014-01-30 01:19:51 +01:00
paging = True
2013-10-18 02:15:26 +02:00
def request(query, params):
2014-05-16 18:07:34 +02:00
params['url'] = search_url.format(query=urlencode({'text': query}),
2014-01-30 01:19:51 +01:00
page=params['pageno'])
2014-05-20 16:57:03 +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'
2013-10-18 02:15:26 +02:00
return params
2014-01-20 02:31:20 +01:00
2013-10-18 02:15:26 +02:00
def response(resp):
results = []
2014-05-20 16:57:03 +02:00
dom = html.fromstring(resp.text)
for result in dom.xpath(results_xpath):
img = result.xpath('.//img')
if not img:
continue
img = img[0]
img_src = 'https:'+img.attrib.get('src')
if not img_src:
continue
href = urljoin(url, result.xpath('.//a')[0].attrib.get('href'))
title = img.attrib.get('alt', '')
results.append({'url': href,
'title': title,
'img_src': img_src,
2014-01-20 02:31:20 +01:00
'template': 'images.html'})
2013-10-18 02:15:26 +02:00
return results