forked from Icycoide/searxng
[feat] add Sogou engine for searxng
Co-authored-by: Bnyro <bnyro@tutanota.com>
This commit is contained in:
parent
71d1504e57
commit
97aa5a779b
6 changed files with 225 additions and 1 deletions
49
searx/engines/sogou_images.py
Normal file
49
searx/engines/sogou_images.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""Sogou-Images: A search engine for retrieving images from Sogou."""
|
||||
|
||||
import json
|
||||
import re
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
# about
|
||||
about = {
|
||||
"website": "https://pic.sogou.com/",
|
||||
"wikidata_id": "Q7554565",
|
||||
"use_official_api": False,
|
||||
"require_api_key": False,
|
||||
"results": "HTML",
|
||||
}
|
||||
|
||||
# engine dependent config
|
||||
categories = ["images"]
|
||||
|
||||
base_url = "https://pic.sogou.com"
|
||||
|
||||
|
||||
def request(query, params):
|
||||
params["url"] = f"{base_url}/pics?query={quote_plus(query)}"
|
||||
return params
|
||||
|
||||
|
||||
def response(resp):
|
||||
results = []
|
||||
match = re.search(r'window\.__INITIAL_STATE__\s*=\s*({.*?});', resp.text, re.S)
|
||||
if not match:
|
||||
return results
|
||||
|
||||
data = json.loads(match.group(1))
|
||||
if "searchList" in data and "searchList" in data["searchList"]:
|
||||
for item in data["searchList"]["searchList"]:
|
||||
results.append(
|
||||
{
|
||||
"template": "images.html",
|
||||
"url": item.get("url", ""),
|
||||
"thumbnail_src": item.get("picUrl", ""),
|
||||
"img_src": item.get("picUrl", ""),
|
||||
"content": item.get("content_major", ""),
|
||||
"title": item.get("title", ""),
|
||||
"source": item.get("ch_site_name", ""),
|
||||
}
|
||||
)
|
||||
|
||||
return results
|
Loading…
Add table
Add a link
Reference in a new issue