.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
360search.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2# pylint: disable=invalid-name
3"""360Search search engine for searxng"""
4
5from urllib.parse import urlencode
6from lxml import html
7
8from searx.utils import extract_text
9
10# Metadata
11about = {
12 "website": "https://www.so.com/",
13 "wikidata_id": "Q10846064",
14 "use_official_api": False,
15 "require_api_key": False,
16 "results": "HTML",
17 "language": "zh",
18}
19
20# Engine Configuration
21categories = ["general"]
22paging = True
23time_range_support = True
24
25time_range_dict = {'day': 'd', 'week': 'w', 'month': 'm', 'year': 'y'}
26
27# Base URL
28base_url = "https://www.so.com"
29
30
31def request(query, params):
32 query_params = {
33 "pn": params["pageno"],
34 "q": query,
35 }
36
37 if time_range_dict.get(params['time_range']):
38 query_params["adv_t"] = time_range_dict.get(params['time_range'])
39
40 params["url"] = f"{base_url}/s?{urlencode(query_params)}"
41 return params
42
43
44def response(resp):
45 dom = html.fromstring(resp.text)
46 results = []
47
48 for item in dom.xpath('//li[contains(@class, "res-list")]'):
49 title = extract_text(item.xpath('.//h3[contains(@class, "res-title")]/a'))
50
51 url = extract_text(item.xpath('.//h3[contains(@class, "res-title")]/a/@data-mdurl'))
52 if not url:
53 url = extract_text(item.xpath('.//h3[contains(@class, "res-title")]/a/@href'))
54
55 content = extract_text(item.xpath('.//p[@class="res-desc"]'))
56 if not content:
57 content = extract_text(item.xpath('.//span[@class="res-list-summary"]'))
58
59 if title and url:
60 results.append(
61 {
62 "title": title,
63 "url": url,
64 "content": content,
65 }
66 )
67
68 return results
request(query, params)
Definition 360search.py:31