@@ -3,10 +3,7 @@
33 Microsoft Academic (Science)
44"""
55
6−from datetime import datetime
7−from json import loads
8−from uuid import uuid4
9−from urllib.parse import urlencode
6+from json import dumps, loads
107from searx.utils import html_to_text
118
129# about
@@ -21,26 +18,25 @@ about = {
2118
2219categories = ['images']
2320paging = True
24−result_url = 'https://academic.microsoft.com/api/search/GetEntityResults?{query}'
21+search_url = 'https://academic.microsoft.com/api/search'
22+_paper_url = 'https://academic.microsoft.com/paper/{id}/reference'
2523
2624
2725def request(query, params):
28− correlation_id = uuid4()
29− msacademic = uuid4()
30− time_now = datetime.now()
31−
32− params['url'] = result_url.format(query=urlencode({'correlationId': correlation_id}))
33− params['cookies']['msacademic'] = str(msacademic)
34− params['cookies']['ai_user'] = 'vhd0H|{now}'.format(now=str(time_now))
26+ params['url'] = search_url
3527 params['method'] = 'POST'
36− params['data'] = {
37− 'Query': '@{query}@'.format(query=query),
38− 'Limit': 10,
39− 'Offset': params['pageno'] - 1,
40− 'Filters': '',
41− 'OrderBy': '',
42− 'SortAscending': False,
43− }
28+ params['headers']['content-type'] = 'application/json; charset=utf-8'
29+ params['data'] = dumps({
30+ 'query': query,
31+ 'queryExpression': '',
32+ 'filters': [],
33+ 'orderBy': 0,
34+ 'skip': (params['pageno'] - 1) * 10,
35+ 'sortAscending': True,
36+ 'take': 10,
37+ 'includeCitationContexts': False,
38+ 'profileId': '',
39+ })
4440
4541 return params
4642
@@ -51,10 +47,13 @@ def response(resp):
5147 if not response_data:
5248 return results
5349
54− for result in response_data['results']:
55− url = _get_url(result)
56− title = result['e']['dn']
57− content = _get_content(result)
50+ for result in response_data['pr']:
51+ if 'dn' not in result['paper']:
52+ continue
53+
54+ title = result['paper']['dn']
55+ content = _get_content(result['paper'])
56+ url = _paper_url.format(id=result['paper']['id'])
5857 results.append({
5958 'url': url,
6059 'title': html_to_text(title),
@@ -64,15 +63,9 @@ def response(resp):
6463 return results
6564
6665
67−def _get_url(result):
68− if 's' in result['e']:
69− return result['e']['s'][0]['u']
70− return 'https://academic.microsoft.com/#/detail/{pid}'.format(pid=result['id'])
71−
72−
7366def _get_content(result):
74− if 'd' in result['e']:
75− content = result['e']['d']
67+ if 'd' in result:
68+ content = result['d']
7669 if len(content) > 300:
7770 return content[:300] + '...'
7871 return content