@cloud411716/fancy-webnovel 0.3.8 → 0.3.10
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
|
@@ -67,6 +67,23 @@ async function extractCategories(page, channel, type) {
|
|
|
67
67
|
|
|
68
68
|
/** 从 __INITIAL_STATE__ 提取当前品类页的作品列表 */
|
|
69
69
|
async function extractBookList(page) {
|
|
70
|
+
// 等 __INITIAL_STATE__ 有书单数据后再提取(防止网络慢时页面 JS 还没注数据)
|
|
71
|
+
try {
|
|
72
|
+
await page.waitForFunction(
|
|
73
|
+
() => {
|
|
74
|
+
const s = window.__INITIAL_STATE__ || {};
|
|
75
|
+
const cands = [s.rank, s.rankData, s.page];
|
|
76
|
+
for (const c of cands) {
|
|
77
|
+
if (c && (c.book_list || c.bookList || c.rankList)) return true;
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
},
|
|
81
|
+
{ timeout: 15000 }
|
|
82
|
+
);
|
|
83
|
+
} catch (waitErr) {
|
|
84
|
+
console.error(` ✗ 等待页面数据超时(15s),可能是网络慢或页面结构变化:${waitErr.message}`);
|
|
85
|
+
return []; // 返回空数组而非抛异常,避免中断整个采集
|
|
86
|
+
}
|
|
70
87
|
return page.evaluate(() => {
|
|
71
88
|
const s = window.__INITIAL_STATE__ || {};
|
|
72
89
|
const cands = [
|
|
@@ -287,7 +304,9 @@ async function scrapeChannel(ch, type) {
|
|
|
287
304
|
|
|
288
305
|
try {
|
|
289
306
|
// 打开入口页
|
|
290
|
-
await page.goto(initUrl, { waitUntil: "networkidle" })
|
|
307
|
+
await page.goto(initUrl, { waitUntil: "networkidle" }).catch(gotoErr => {
|
|
308
|
+
console.error(` ✗ 打开入口页失败:${gotoErr.message}`);
|
|
309
|
+
});
|
|
291
310
|
|
|
292
311
|
// 等待登录(用户可在此时手动登录)
|
|
293
312
|
if (LOGIN_WAIT > 0) {
|
|
@@ -404,7 +423,9 @@ async function scrapeChannel(ch, type) {
|
|
|
404
423
|
console.log(` [${ci + 1}/${categories.length}] ${cat.name}`);
|
|
405
424
|
|
|
406
425
|
try {
|
|
407
|
-
await page.goto(`https://fanqienovel.com${cat.href}`, { waitUntil: "networkidle" })
|
|
426
|
+
await page.goto(`https://fanqienovel.com${cat.href}`, { waitUntil: "networkidle" }).catch(gotoErr => {
|
|
427
|
+
console.error(` ✗ 打开品类页失败:${gotoErr.message}`);
|
|
428
|
+
});
|
|
408
429
|
await page.waitForTimeout(2500);
|
|
409
430
|
await scrollLoad(page, 2);
|
|
410
431
|
|