.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
sogou_wechat.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
"""Sogou-WeChat search engine for retrieving WeChat Article from Sogou"""
3
4
from urllib.parse import urlencode
5
from datetime import datetime
6
import re
7
from lxml import html
8
9
from searx.utils import extract_text
10
11
# Metadata
12
about = {
13
"website": "https://weixin.sogou.com/",
14
"use_official_api": False,
15
"require_api_key": False,
16
"results": "HTML",
17
"language": "zh",
18
}
19
20
# Engine Configuration
21
categories = ["news"]
22
paging = True
23
24
# Base URL
25
base_url = "https://weixin.sogou.com"
26
27
28
def request(query, params):
29
query_params = {
30
"query": query,
31
"page": params["pageno"],
32
"type": 2,
33
}
34
35
params["url"] = f"{base_url}/weixin?{urlencode(query_params)}"
36
return params
37
38
39
def response(resp):
40
dom = html.fromstring(resp.text)
41
results = []
42
43
for item in dom.xpath('//li[contains(@id, "sogou_vr_")]'):
44
title = extract_text(item.xpath('.//h3/a'))
45
url = extract_text(item.xpath('.//h3/a/@href'))
46
47
if url.startswith("/link?url="):
48
url = f"{base_url}{url}"
49
50
content = extract_text(item.xpath('.//p[@class="txt-info"]'))
51
if not content:
52
content = extract_text(item.xpath('.//p[contains(@class, "txt-info")]'))
53
54
thumbnail = extract_text(item.xpath('.//div[@class="img-box"]/a/img/@src'))
55
if thumbnail and thumbnail.startswith("//"):
56
thumbnail = f"https:{thumbnail}"
57
58
published_date = None
59
timestamp = extract_text(item.xpath('.//script[contains(text(), "timeConvert")]'))
60
if timestamp:
61
match = re.search(r"timeConvert\('(\d+)'\)", timestamp)
62
if match:
63
published_date = datetime.fromtimestamp(int(match.group(1)))
64
65
if title and url:
66
results.append(
67
{
68
"title": title,
69
"url": url,
70
"content": content,
71
'thumbnail': thumbnail,
72
"publishedDate": published_date,
73
}
74
)
75
76
return results
searxng
searx
engines
sogou_wechat.py
Generated on Sat Mar 8 2025 14:18:40 for .oO SearXNG Developer Documentation Oo. by
1.13.2