@sovovs/bycli 2.1.22 → 2.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli-manifest.json +2 -1
- package/clis/weixin/search.js +11 -8
- package/package.json +1 -1
package/cli-manifest.json
CHANGED
|
@@ -28309,7 +28309,7 @@
|
|
|
28309
28309
|
},
|
|
28310
28310
|
{
|
|
28311
28311
|
"site": "weixin",
|
|
28312
|
-
"name": "
|
|
28312
|
+
"name": "sougousearch",
|
|
28313
28313
|
"description": "使用搜狗微信搜索公众号文章;如需导出正文 Markdown,请使用 weixin download 处理公众号文章链接",
|
|
28314
28314
|
"access": "read",
|
|
28315
28315
|
"domain": "weixin.sogou.com",
|
|
@@ -28342,6 +28342,7 @@
|
|
|
28342
28342
|
"rank",
|
|
28343
28343
|
"page",
|
|
28344
28344
|
"title",
|
|
28345
|
+
"account",
|
|
28345
28346
|
"url",
|
|
28346
28347
|
"summary",
|
|
28347
28348
|
"publish_time"
|
package/clis/weixin/search.js
CHANGED
|
@@ -11,14 +11,14 @@ function normalizePositiveInteger(value, name, defaultValue, maxValue) {
|
|
|
11
11
|
const text = String(value).trim();
|
|
12
12
|
if (!/^\d+$/.test(text)) {
|
|
13
13
|
throw new ArgumentError(
|
|
14
|
-
`weixin
|
|
14
|
+
`weixin sougousearch --${name} must be a positive integer`,
|
|
15
15
|
`Pass --${name} as a whole number${maxValue ? ` from 1 to ${maxValue}` : ' greater than 0'}.`,
|
|
16
16
|
);
|
|
17
17
|
}
|
|
18
18
|
const parsed = Number(text);
|
|
19
19
|
if (!Number.isSafeInteger(parsed) || parsed < 1 || (maxValue && parsed > maxValue)) {
|
|
20
20
|
throw new ArgumentError(
|
|
21
|
-
`weixin
|
|
21
|
+
`weixin sougousearch --${name} is out of range`,
|
|
22
22
|
`Pass --${name} as a whole number${maxValue ? ` from 1 to ${maxValue}` : ' greater than 0'}.`,
|
|
23
23
|
);
|
|
24
24
|
}
|
|
@@ -69,9 +69,11 @@ function buildExtractSearchResultsEvaluate() {
|
|
|
69
69
|
const extracted = cards.map((item) => {
|
|
70
70
|
const linkEl = item.querySelector('h3 a[href]');
|
|
71
71
|
const summaryEl = item.querySelector('p.txt-info');
|
|
72
|
+
const accountEl = item.querySelector('.s-p .all-time-y2');
|
|
72
73
|
const timeEl = item.querySelector('.s-p .s2');
|
|
73
74
|
return {
|
|
74
75
|
title: clean(linkEl && linkEl.textContent),
|
|
76
|
+
account: clean(accountEl && accountEl.textContent),
|
|
75
77
|
url: absolutize(linkEl && linkEl.getAttribute('href')),
|
|
76
78
|
summary: clean(summaryEl && summaryEl.textContent),
|
|
77
79
|
publish_time: clean(timeEl && timeEl.textContent),
|
|
@@ -90,7 +92,7 @@ function buildExtractSearchResultsEvaluate() {
|
|
|
90
92
|
|
|
91
93
|
export const weixinSearchCommand = cli({
|
|
92
94
|
site: 'weixin',
|
|
93
|
-
name: '
|
|
95
|
+
name: 'sougousearch',
|
|
94
96
|
access: 'read',
|
|
95
97
|
description: '使用搜狗微信搜索公众号文章;如需导出正文 Markdown,请使用 weixin download 处理公众号文章链接',
|
|
96
98
|
domain: SOGOU_WEIXIN_DOMAIN,
|
|
@@ -101,7 +103,7 @@ export const weixinSearchCommand = cli({
|
|
|
101
103
|
{ name: 'page', type: 'int', default: 1, help: '结果页码,从 1 开始' },
|
|
102
104
|
{ name: 'limit', type: 'int', default: 10, help: '返回条数,最大 10' },
|
|
103
105
|
],
|
|
104
|
-
columns: ['rank', 'page', 'title', 'url', 'summary', 'publish_time'],
|
|
106
|
+
columns: ['rank', 'page', 'title', 'account', 'url', 'summary', 'publish_time'],
|
|
105
107
|
func: async (page, kwargs) => {
|
|
106
108
|
const query = String(kwargs.query ?? '').trim();
|
|
107
109
|
if (!query) {
|
|
@@ -119,11 +121,11 @@ export const weixinSearchCommand = cli({
|
|
|
119
121
|
payload = await page.evaluate(buildExtractSearchResultsEvaluate());
|
|
120
122
|
} catch (error) {
|
|
121
123
|
const detail = error instanceof Error ? error.message : String(error);
|
|
122
|
-
throw new CommandExecutionError('weixin
|
|
124
|
+
throw new CommandExecutionError('weixin sougousearch failed while loading Sogou results', detail);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
if (!payload || typeof payload !== 'object' || !Array.isArray(payload.rows)) {
|
|
126
|
-
throw new CommandExecutionError('weixin
|
|
128
|
+
throw new CommandExecutionError('weixin sougousearch returned an unreadable browser payload', 'Sogou Weixin may have changed its result page structure.');
|
|
127
129
|
}
|
|
128
130
|
if (payload.blocked) {
|
|
129
131
|
throw new CommandExecutionError('Sogou Weixin blocked this search request', 'Open weixin.sogou.com in Chrome and complete any verification before retrying.');
|
|
@@ -134,16 +136,17 @@ export const weixinSearchCommand = cli({
|
|
|
134
136
|
|
|
135
137
|
const rows = payload.rows;
|
|
136
138
|
if (rows.length === 0 && payload.empty) {
|
|
137
|
-
throw new EmptyResultError('weixin
|
|
139
|
+
throw new EmptyResultError('weixin sougousearch', 'Try a different keyword or a different page number.');
|
|
138
140
|
}
|
|
139
141
|
if (rows.length === 0) {
|
|
140
|
-
throw new CommandExecutionError('weixin
|
|
142
|
+
throw new CommandExecutionError('weixin sougousearch did not expose article result cards', 'Sogou Weixin may have changed its selectors or returned a transient shell page.');
|
|
141
143
|
}
|
|
142
144
|
|
|
143
145
|
return rows.slice(0, limit).map((row, index) => ({
|
|
144
146
|
rank: (pageNo - 1) * 10 + index + 1,
|
|
145
147
|
page: pageNo,
|
|
146
148
|
title: row.title,
|
|
149
|
+
account: row.account,
|
|
147
150
|
url: row.url,
|
|
148
151
|
summary: row.summary,
|
|
149
152
|
publish_time: row.publish_time,
|