.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
sogou_images.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""Sogou-Images: A search engine for retrieving images from Sogou."""
3
4import json
5import re
6from urllib.parse import urlencode
7
8# about
9about = {
10 "website": "https://pic.sogou.com/",
11 "wikidata_id": "Q7554565",
12 "use_official_api": False,
13 "require_api_key": False,
14 "results": "HTML",
15}
16
17# engine dependent config
18categories = ["images"]
19paging = True
20
21base_url = "https://pic.sogou.com"
22
23
24def request(query, params):
25 query_params = {
26 "query": query,
27 "start": (params["pageno"] - 1) * 48,
28 }
29
30 params["url"] = f"{base_url}/pics?{urlencode(query_params)}"
31 return params
32
33
34def response(resp):
35 results = []
36 match = re.search(r'window\.__INITIAL_STATE__\s*=\s*({.*?});', resp.text, re.S)
37 if not match:
38 return results
39
40 data = json.loads(match.group(1))
41 if "searchList" in data and "searchList" in data["searchList"]:
42 for item in data["searchList"]["searchList"]:
43 results.append(
44 {
45 "template": "images.html",
46 "url": item.get("url", ""),
47 "thumbnail_src": item.get("picUrl", ""),
48 "img_src": item.get("picUrl", ""),
49 "content": item.get("content_major", ""),
50 "title": item.get("title", ""),
51 "source": item.get("ch_site_name", ""),
52 }
53 )
54
55 return results