@cloud411716/fancy-webnovel 0.2.10 → 0.2.12
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
|
@@ -312,49 +312,60 @@ async function scrapeChannel(ch, type) {
|
|
|
312
312
|
const intercepted = [];
|
|
313
313
|
const seen = new Set();
|
|
314
314
|
|
|
315
|
+
// 先注册拦截器,再导航到目标页(避免漏掉 initial 请求)
|
|
316
|
+
context.on("request", req => {
|
|
317
|
+
const url = req.url();
|
|
318
|
+
if (seen.has(url)) return;
|
|
319
|
+
if (/\.(css|woff|jpg|png|ico)/.test(url)) return;
|
|
320
|
+
if (!url.includes("fanqie")) return;
|
|
321
|
+
seen.add(url);
|
|
322
|
+
console.log(`[REQ] ${url}`);
|
|
323
|
+
});
|
|
324
|
+
|
|
315
325
|
page.on("response", async (resp) => {
|
|
316
326
|
const url = resp.url();
|
|
317
|
-
const ct = resp.headers()["content-type"] || "";
|
|
318
|
-
|
|
319
|
-
if (!ct.includes("json") && !ct.includes("text")) return;
|
|
320
|
-
// 跳过静态资源
|
|
327
|
+
const ct = (resp.headers()["content-type"] || "").toLowerCase();
|
|
328
|
+
if (seen.has(url)) return;
|
|
329
|
+
if (!ct.includes("json") && !ct.includes("text") && !url.includes("api")) return;
|
|
321
330
|
if (/\.(css|woff|jpg|png|ico)/.test(url)) return;
|
|
322
331
|
try {
|
|
323
332
|
const body = await resp.text();
|
|
324
333
|
if (!body || body.length < 50) return;
|
|
325
|
-
// 尝试解析 JSON
|
|
326
334
|
let parsed;
|
|
327
335
|
try { parsed = JSON.parse(body); } catch { return; }
|
|
328
|
-
// 找含书籍数据的响应
|
|
329
336
|
const str = JSON.stringify(parsed);
|
|
330
337
|
if (str.includes("bookId") || str.includes("book_name") || str.includes("bookName") || str.includes("authorName")) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
338
|
+
console.log(`[JSON] ${url}`);
|
|
339
|
+
console.log(` 预览: ${str.slice(0, 300)}`);
|
|
340
|
+
intercepted.push({ url, preview: str.slice(0, 400) });
|
|
335
341
|
}
|
|
336
342
|
} catch {}
|
|
337
343
|
});
|
|
338
344
|
|
|
339
|
-
//
|
|
345
|
+
// 直接导航到品类页(不用 waitUntil,避免卡住)
|
|
340
346
|
const cats = await extractCategories(page, ch, type);
|
|
341
347
|
if (!cats.length) {
|
|
342
|
-
await
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
348
|
+
await page.goto(`https://fanqienovel.com/rank/${ch}_${type}_${initCatId}`);
|
|
349
|
+
await page.waitForTimeout(3000);
|
|
350
|
+
const moreCats = await extractCategories(page, ch, type);
|
|
351
|
+
if (moreCats.length) {
|
|
352
|
+
console.log(` 发现 ${moreCats.length} 个品类`);
|
|
353
|
+
for (const c of moreCats.slice(0, 3)) {
|
|
354
|
+
console.log(` 探测品类: ${c.name} → ${c.href}`);
|
|
355
|
+
await page.goto(`https://fanqienovel.com${c.href}`);
|
|
356
|
+
await page.waitForTimeout(2000);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
console.log(` 发现 ${cats.length} 个品类`);
|
|
361
|
+
for (const c of cats.slice(0, 3)) {
|
|
362
|
+
console.log(` 探测品类: ${c.name} → ${c.href}`);
|
|
363
|
+
await page.goto(`https://fanqienovel.com${c.href}`);
|
|
364
|
+
await page.waitForTimeout(2000);
|
|
365
|
+
}
|
|
350
366
|
}
|
|
351
367
|
|
|
352
|
-
console.log(`\n===
|
|
353
|
-
for (const { url, preview } of intercepted) {
|
|
354
|
-
console.log(`URL: ${url}`);
|
|
355
|
-
console.log(`预览: ${preview}`);
|
|
356
|
-
console.log("---");
|
|
357
|
-
}
|
|
368
|
+
console.log(`\n=== 共拦截到 ${intercepted.length} 个含书籍数据的接口 ===`);
|
|
358
369
|
await browser.close();
|
|
359
370
|
return null;
|
|
360
371
|
}
|
|
@@ -101,14 +101,12 @@ export const scan = {
|
|
|
101
101
|
fileList,
|
|
102
102
|
``,
|
|
103
103
|
`请执行以下步骤:`,
|
|
104
|
+
`0. **禁止**使用覆盖的方式写文件,**必须**使用追加的方式`,
|
|
104
105
|
`1. 读取上述生成的原始数据文件`,
|
|
105
106
|
`2. 分析爆款书籍的题材、卖点、节奏、人设等特征`,
|
|
106
107
|
`3. 生成扫榜报告(包含:市场趋势、热门题材分析、用户画像、竞争度评估)`,
|
|
107
108
|
`4. 给出 3-5 个可行的选题方向建议`,
|
|
108
|
-
`5.
|
|
109
|
-
` touch ${topicFile}\n` +
|
|
110
|
-
` echo "你的报告内容" >> ${topicFile}\n` +
|
|
111
|
-
` (使用 tee -a 或 >> ,不要覆盖现有内容)`,
|
|
109
|
+
`5. 将完整分析报告追加写入:${topicFile}`,
|
|
112
110
|
``,
|
|
113
111
|
`报告要求:`,
|
|
114
112
|
`- 客观分析数据,不臆测`,
|