on master help sign in
[fix] update devianart engine
commit7177c9e12f238aeac66e450ee94c849c927dd407 authorAdam Tauber <asciimoo@gmail.com> dateWed 16 Oct 2019, 14:42 (7 years ago) parent6ca1622
1 file changed+22−23
searx/engines/deviantart.py+22−23
searx/engines/deviantart.py+22−23
@@ -24,7 +24,7 @@ time_range_support = True
2424
2525# search-url
2626base_url = 'https://www.deviantart.com/'
27−search_url = base_url + 'browse/all/?offset={offset}&{query}'
27+search_url = base_url + 'search?page={page}&{query}'
2828time_range_url = '&order={range}'
2929
3030time_range_dict = {'day': 11,
@@ -37,9 +37,8 @@ def request(query, params):
3737 if params['time_range'] and params['time_range'] not in time_range_dict:
3838 return params
3939
40− offset = (params['pageno'] - 1) * 24
4140
42− params['url'] = search_url.format(offset=offset,
41+ params['url'] = search_url.format(page=params['pageno'],
4342 query=urlencode({'q': query}))
4443 if params['time_range'] in time_range_dict:
4544 params['url'] += time_range_url.format(range=time_range_dict[params['time_range']])
@@ -57,28 +56,28 @@ def response(resp):
5756
5857 dom = html.fromstring(resp.text)
5958
60− regex = re.compile(r'\/200H\/')
6159
6260 # parse results
63− for result in dom.xpath('.//span[@class="thumb wide"]'):
64− link = result.xpath('.//a[@class="torpedo-thumb-link"]')[0]
65− url = link.attrib.get('href')
66− title = extract_text(result.xpath('.//span[@class="title"]'))
67− thumbnail_src = link.xpath('.//img')[0].attrib.get('src')
68− img_src = regex.sub('/', thumbnail_src)
69−
70− # http to https, remove domain sharding
71− thumbnail_src = re.sub(r"https?://(th|fc)\d+.", "https://th01.", thumbnail_src)
72− thumbnail_src = re.sub(r"http://", "https://", thumbnail_src)
73−
74− url = re.sub(r"http://(.*)\.deviantart\.com/", "https://\\1.deviantart.com/", url)
75−
76− # append result
77− results.append({'url': url,
78− 'title': title,
79− 'img_src': img_src,
80− 'thumbnail_src': thumbnail_src,
81− 'template': 'images.html'})
61+ for row in dom.xpath('//div[contains(@data-hook, "content_row")]'):
62+ for result in row.xpath('./div'):
63+ link = result.xpath('.//a[@data-hook="deviation_link"]')[0]
64+ url = link.attrib.get('href')
65+ title = link.attrib.get('title')
66+ thumbnail_src = result.xpath('.//img')[0].attrib.get('src')
67+ img_src = thumbnail_src
68+
69+ # http to https, remove domain sharding
70+ thumbnail_src = re.sub(r"https?://(th|fc)\d+.", "https://th01.", thumbnail_src)
71+ thumbnail_src = re.sub(r"http://", "https://", thumbnail_src)
72+
73+ url = re.sub(r"http://(.*)\.deviantart\.com/", "https://\\1.deviantart.com/", url)
74+
75+ # append result
76+ results.append({'url': url,
77+ 'title': title,
78+ 'img_src': img_src,
79+ 'thumbnail_src': thumbnail_src,
80+ 'template': 'images.html'})
8281
8382 # return results
8483 return results