@cloud411716/fancy-webnovel 0.3.9 → 0.3.11

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -68,17 +68,22 @@ async function extractCategories(page, channel, type) {
68
68
  /** 从 __INITIAL_STATE__ 提取当前品类页的作品列表 */
69
69
  async function extractBookList(page) {
70
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
- );
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.log(` ✗ 等待页面数据超时(15s),可能是网络慢或页面结构变化:${waitErr.message}`);
85
+ return []; // 返回空数组而非抛异常,避免中断整个采集
86
+ }
82
87
  return page.evaluate(() => {
83
88
  const s = window.__INITIAL_STATE__ || {};
84
89
  const cands = [
@@ -299,7 +304,9 @@ async function scrapeChannel(ch, type) {
299
304
 
300
305
  try {
301
306
  // 打开入口页
302
- await page.goto(initUrl, { waitUntil: "networkidle" });
307
+ await page.goto(initUrl, { waitUntil: "networkidle" }).catch(gotoErr => {
308
+ console.log(` ✗ 打开入口页失败:${gotoErr.message}`);
309
+ });
303
310
 
304
311
  // 等待登录(用户可在此时手动登录)
305
312
  if (LOGIN_WAIT > 0) {
@@ -310,7 +317,7 @@ async function scrapeChannel(ch, type) {
310
317
  // 连通性自检
311
318
  const probe = await probePage(page);
312
319
  if (!probe.host || probe.host.indexOf("fanqie") === -1) {
313
- console.error(
320
+ console.log(
314
321
  ` ✗ 当前页面非番茄(host=${probe.host}),可能被重定向到登录/验证页,已跳过。`
315
322
  );
316
323
  return null;
@@ -416,7 +423,9 @@ async function scrapeChannel(ch, type) {
416
423
  console.log(` [${ci + 1}/${categories.length}] ${cat.name}`);
417
424
 
418
425
  try {
419
- 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.log(` ✗ 打开品类页失败:${gotoErr.message}`);
428
+ });
420
429
  await page.waitForTimeout(2500);
421
430
  await scrollLoad(page, 2);
422
431
 
@@ -451,7 +460,7 @@ async function scrapeChannel(ch, type) {
451
460
 
452
461
  bodyLines.push("---", "");
453
462
  } catch (catErr) {
454
- console.error(
463
+ console.log(
455
464
  ` [fanqie] 品类 ${cat.name} 处理出错,跳过: ${catErr && catErr.message ? catErr.message : catErr}`
456
465
  );
457
466
  bodyLines.push(`## ${cat.name} — 采集失败`, "", "---", "");
@@ -491,7 +500,7 @@ async function main() {
491
500
  written++;
492
501
  console.log(` ✓ 已保存: ${filepath}`);
493
502
  } catch (chErr) {
494
- console.error(
503
+ console.log(
495
504
  `[fanqie] ${channelLabel(ch)}${typeLabel(ty)} 采集失败,跳过: ${chErr && chErr.message ? chErr.message : chErr}`
496
505
  );
497
506
  }