@@ -6,13 +6,14 @@
6# @using-api no (TODO, rewrite to api)
6# @using-api no (TODO, rewrite to api)
7# @results HTML
7# @results HTML
8# @stable no (HTML can change)
8# @stable no (HTML can change)
9−# @parse url, title, thumbnail, img_src
9+# @parse url, title, thumbnail_src, img_src
11# @todo rewrite to api
11# @todo rewrite to api
13from urllib import urlencode
13from urllib import urlencode
14from urlparse import urljoin
14from urlparse import urljoin
15from lxml import html
15from lxml import html
17# engine dependent config
18# engine dependent config
18categories = ['images']
19categories = ['images']
@@ -43,18 +44,22 @@ def response(resp):
44 dom = html.fromstring(resp.text)
45 dom = html.fromstring(resp.text)
47+ regex = re.compile('\/200H\/')
46 # parse results
49 # parse results
47 for result in dom.xpath('//div[contains(@class, "tt-a tt-fh")]'):
50 for result in dom.xpath('//div[contains(@class, "tt-a tt-fh")]'):
48 link = result.xpath('.//a[contains(@class, "thumb")]')[0]
51 link = result.xpath('.//a[contains(@class, "thumb")]')[0]
49 url = urljoin(base_url, link.attrib.get('href'))
52 url = urljoin(base_url, link.attrib.get('href'))
50 title_links = result.xpath('.//span[@class="details"]//a[contains(@class, "t")]') # noqa
53 title_links = result.xpath('.//span[@class="details"]//a[contains(@class, "t")]') # noqa
51 title = ''.join(title_links[0].xpath('.//text()'))
54 title = ''.join(title_links[0].xpath('.//text()'))
52− img_src = link.xpath('.//img')[0].attrib['src']
55+ thumbnail_src = link.xpath('.//img')[0].attrib['src']
56+ img_src = regex.sub('/', thumbnail_src)
54 # append result
58 # append result
55 results.append({'url': url,
59 results.append({'url': url,
56 'title': title,
60 'title': title,
57 'img_src': img_src,
61 'img_src': img_src,
62+ 'thumbnail_src': thumbnail_src,
58 'template': 'images.html'})
63 'template': 'images.html'})
60 # return results
65 # return results