mirror of
https://github.com/searxng/searxng.git
synced 2025-03-13 07:52:40 +00:00
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
# 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
|