@@ -11,8 +11,8 @@
1111"""
1212
1313from lxml import html
14−import re
1514from searx.url_utils import urlencode, urljoin
15+from searx.engines.xpath import extract_text
1616
1717# engine dependent config
1818categories = ['images']
@@ -34,41 +34,18 @@ def request(query, params):
3434def response(resp):
3535 results = []
3636
37− # get links from result-text
38− regex = re.compile('(</a>|<a)')
39− results_parts = re.split(regex, resp.text)
40−
41− cur_element = ''
42−
43− # iterate over link parts
44− for result_part in results_parts:
37+ dom = html.fromstring(resp.text)
38+ for res in dom.xpath('//div[@class="List-item MainListing"]'):
4539 # processed start and end of link
46− if result_part == '<a':
47− cur_element = result_part
48− continue
49− elif result_part != '</a>':
50− cur_element += result_part
51− continue
52−
53− cur_element += result_part
54−
55− # fix xml-error
56− cur_element = cur_element.replace('"></a>', '"/></a>')
57−
58− dom = html.fromstring(cur_element)
59− link = dom.xpath('//a')[0]
40+ link = res.xpath('//a')[0]
6041
6142 url = urljoin(base_url, link.attrib.get('href'))
62− title = link.attrib.get('title', '')
43+ title = extract_text(link)
6344
64− thumbnail_src = urljoin(base_url, link.xpath('.//img')[0].attrib['src'])
45+ thumbnail_src = urljoin(base_url, res.xpath('.//img')[0].attrib['src'])
6546 # TODO: get image with higher resolution
6647 img_src = thumbnail_src
6748
68− # check if url is showing to a photo
69− if '/photo/' not in url:
70− continue
71−
7249 # append result
7350 results.append({'url': url,
7451 'title': title,