.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
stract.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Stract is an independent open source search engine. At this state, it's
3still in beta and hence this implementation will need to be updated once beta
4ends.
5
6"""
7
8from json import dumps
9from searx.utils import searx_useragent
10
11about = {
12 "website": "https://stract.com/",
13 "use_official_api": True,
14 "official_api_documentation": "https://stract.com/beta/api/docs/#/search/api",
15 "require_api_key": False,
16 "results": "JSON",
17}
18categories = ['general']
19paging = True
20
21search_url = "https://stract.com/beta/api/search"
22
23
24def request(query, params):
25 params['url'] = search_url
26 params['method'] = "POST"
27 params['headers'] = {
28 'Accept': 'application/json',
29 'Content-Type': 'application/json',
30 'User-Agent': searx_useragent(),
31 }
32 params['data'] = dumps({'query': query, 'page': params['pageno'] - 1})
33
34 return params
35
36
37def response(resp):
38 results = []
39
40 for result in resp.json()["webpages"]:
41 results.append(
42 {
43 'url': result['url'],
44 'title': result['title'],
45 'content': ''.join(fragment['text'] for fragment in result['snippet']['text']['fragments']),
46 }
47 )
48
49 return results
request(query, params)
Definition stract.py:24