123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. from urllib import urlencode
  3. #from json import loads
  4. from urlparse import urljoin
  5. from lxml import html
  6. from time import time
  7. categories = ['images']
  8. url = 'https://secure.flickr.com/'
  9. search_url = url+'search/?{query}&page={page}'
  10. results_xpath = '//div[@class="view display-item-tile"]/figure/div'
  11. paging = True
  12. def request(query, params):
  13. params['url'] = search_url.format(query=urlencode({'text': query}),
  14. page=params['pageno'])
  15. time_string = str(int(time())-3)
  16. params['cookies']['BX'] = '3oqjr6d9nmpgl&b=3&s=dh'
  17. params['cookies']['xb'] = '421409'
  18. params['cookies']['localization'] = 'en-us'
  19. params['cookies']['flrbp'] = time_string +\
  20. '-3a8cdb85a427a33efda421fbda347b2eaf765a54'
  21. params['cookies']['flrbs'] = time_string +\
  22. '-ed142ae8765ee62c9ec92a9513665e0ee1ba6776'
  23. params['cookies']['flrb'] = '9'
  24. return params
  25. def response(resp):
  26. results = []
  27. dom = html.fromstring(resp.text)
  28. for result in dom.xpath(results_xpath):
  29. img = result.xpath('.//img')
  30. if not img:
  31. continue
  32. img = img[0]
  33. img_src = 'https:'+img.attrib.get('src')
  34. if not img_src:
  35. continue
  36. href = urljoin(url, result.xpath('.//a')[0].attrib.get('href'))
  37. title = img.attrib.get('alt', '')
  38. results.append({'url': href,
  39. 'title': title,
  40. 'img_src': img_src,
  41. 'template': 'images.html'})
  42. return results