mirror of
https://github.com/searxng/searxng.git
synced 2024-11-19 02:40:11 +01:00
[enh] mediawiki engine added
This commit is contained in:
parent
b15cd55546
commit
75a2a6fb73
23
searx/engines/mediawiki.py
Normal file
23
searx/engines/mediawiki.py
Normal file
@ -0,0 +1,23 @@
|
||||
from json import loads
|
||||
from urllib import urlencode, quote
|
||||
|
||||
url = 'https://en.wikipedia.org/'
|
||||
|
||||
number_of_results = 10
|
||||
|
||||
def request(query, params):
|
||||
search_url = url + 'w/api.php?action=query&list=search&{query}&srprop=timestamp&format=json'
|
||||
params['url'] = search_url.format(query=urlencode({'srsearch': query}))
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
search_results = loads(resp.text)
|
||||
results = []
|
||||
res = search_results.get('query', {}).get('search', [])
|
||||
if not len(res):
|
||||
return results
|
||||
for result in res[:int(number_of_results)]:
|
||||
results.append({'url': url + 'wiki/' + quote(result['title'].replace(' ', '_').encode('utf-8')), 'title': result['title']})
|
||||
return results
|
||||
|
Loading…
Reference in New Issue
Block a user