@@ -11,8 +11,8 @@
13from lxml import html
13from lxml import html
15from searx.url_utils import urlencode, urljoin
14from searx.url_utils import urlencode, urljoin
15+from searx.engines.xpath import extract_text
17# engine dependent config
17# engine dependent config
18categories = ['images']
18categories = ['images']
@@ -34,41 +34,18 @@ def request(query, params):
34def response(resp):
34def response(resp):
35 results = []
35 results = []
37− # get links from result-text
37+ dom = html.fromstring(resp.text)
38− regex = re.compile('(</a>|<a)')
38+ for res in dom.xpath('//div[@class="List-item MainListing"]'):
39− results_parts = re.split(regex, resp.text)
43− # iterate over link parts
44− for result_part in results_parts:
45 # processed start and end of link
39 # processed start and end of link
46− if result_part == '<a':
47− cur_element = result_part
49− elif result_part != '</a>':
50− cur_element += result_part
53− cur_element += result_part
56− cur_element = cur_element.replace('"></a>', '"/></a>')
58− dom = html.fromstring(cur_element)
59− link = dom.xpath('//a')[0]
40+ link = res.xpath('//a')[0]
61 url = urljoin(base_url, link.attrib.get('href'))
42 url = urljoin(base_url, link.attrib.get('href'))
62− title = link.attrib.get('title', '')
43+ title = extract_text(link)
64− thumbnail_src = urljoin(base_url, link.xpath('.//img')[0].attrib['src'])
45+ thumbnail_src = urljoin(base_url, res.xpath('.//img')[0].attrib['src'])
65 # TODO: get image with higher resolution
46 # TODO: get image with higher resolution
66 img_src = thumbnail_src
47 img_src = thumbnail_src
68− # check if url is showing to a photo
69− if '/photo/' not in url:
72 # append result
49 # append result
73 results.append({'url': url,
50 results.append({'url': url,
74 'title': title,
51 'title': title,