@cloud411716/fancy-webnovel 0.3.7 → 0.3.9
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/package.json
CHANGED
|
@@ -149,10 +149,17 @@ function spawnScraper(script, extraArgs, outDir) {
|
|
|
149
149
|
let out = '';
|
|
150
150
|
p.stdout.on('data', d => { out += d.toString(); });
|
|
151
151
|
p.on('close', (code) => {
|
|
152
|
-
|
|
152
|
+
const outTrimmed = out.trim();
|
|
153
|
+
// scraper 内部吞掉了很多错误(返回 null 但 exit 0),通过 stdout 里的失败标识判断
|
|
154
|
+
const softFail = outTrimmed.includes('已跳过') ||
|
|
155
|
+
outTrimmed.includes('采集失败') ||
|
|
156
|
+
outTrimmed.includes('✗') ||
|
|
157
|
+
outTrimmed.includes('failed');
|
|
158
|
+
if (code === 0 && !softFail && outTrimmed) {
|
|
153
159
|
resolve({ ok: true, output: out });
|
|
154
160
|
} else {
|
|
155
|
-
|
|
161
|
+
// 把 stdout 末 500 字符当错误摘要
|
|
162
|
+
resolve({ ok: false, output: out, error: outTrimmed.slice(-500) || `exit ${code}` });
|
|
156
163
|
}
|
|
157
164
|
});
|
|
158
165
|
p.on('error', e => resolve({ ok: false, output: '', error: e.message }));
|
|
@@ -67,6 +67,18 @@ async function extractCategories(page, channel, type) {
|
|
|
67
67
|
|
|
68
68
|
/** 从 __INITIAL_STATE__ 提取当前品类页的作品列表 */
|
|
69
69
|
async function extractBookList(page) {
|
|
70
|
+
// 等 __INITIAL_STATE__ 有书单数据后再提取(防止网络慢时页面 JS 还没注数据)
|
|
71
|
+
await page.waitForFunction(
|
|
72
|
+
() => {
|
|
73
|
+
const s = window.__INITIAL_STATE__ || {};
|
|
74
|
+
const cands = [s.rank, s.rankData, s.page];
|
|
75
|
+
for (const c of cands) {
|
|
76
|
+
if (c && (c.book_list || c.bookList || c.rankList)) return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
},
|
|
80
|
+
{ timeout: 15000 }
|
|
81
|
+
);
|
|
70
82
|
return page.evaluate(() => {
|
|
71
83
|
const s = window.__INITIAL_STATE__ || {};
|
|
72
84
|
const cands = [
|