@cloud411716/fancy-webnovel 0.2.19 → 0.2.21

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.2.19",
3
+ "version": "0.2.21",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -139,15 +139,17 @@ async function scrapeRank(rankTypeId, channelId) {
139
139
 
140
140
  // 布局检测:先找含"序号"/"作者"/"作品"表头的表格,有则为布局A(表格),无为布局B(交替行)
141
141
  data = await page.evaluate(() => {
142
- // ── 布局 A:表格型(表头含"序号""作者""作品") ──
142
+ // ── 布局 A:表格型(表头在第一行 <tr> 的 <td> 里,含"序号""作者""作品") ──
143
143
  var tables = document.querySelectorAll('table');
144
144
  for (var ti = 0; ti < tables.length; ti++) {
145
- var ths = tables[ti].querySelectorAll('th');
146
- var headerText = Array.from(ths).map(function(th) { return th.innerText.trim(); }).join('');
145
+ var firstRow = tables[ti].querySelector('tr');
146
+ if (!firstRow) continue;
147
+ var headerCells = firstRow.querySelectorAll('td,th');
148
+ var headerText = Array.from(headerCells).map(function(c) { return c.innerText.trim(); }).join('');
147
149
  if (headerText.indexOf('序号') >= 0 && headerText.indexOf('作者') >= 0 && headerText.indexOf('作品') >= 0) {
148
150
  var rows = tables[ti].querySelectorAll('tr');
149
151
  var books = [];
150
- for (var ri = 0; ri < rows.length; ri++) {
152
+ for (var ri = 1; ri < rows.length; ri++) {
151
153
  var cells = rows[ri].querySelectorAll('td');
152
154
  if (cells.length < 3) continue;
153
155
  var rankCell = cells[0].innerText.trim();
@@ -155,10 +157,9 @@ async function scrapeRank(rankTypeId, channelId) {
155
157
  var author = cells[1].innerText.trim();
156
158
  var titleLink = cells[2].querySelector('a');
157
159
  var title = titleLink ? titleLink.innerText.trim() : cells[2].innerText.trim();
158
- var novelLink = cells[2].querySelector('a');
159
160
  var novelid = '';
160
- if (novelLink) {
161
- var m = (novelLink.getAttribute('href') || '').match(/novelid=([0-9]+)/);
161
+ if (titleLink) {
162
+ var m = (titleLink.getAttribute('href') || '').match(/novelid=([0-9]+)/);
162
163
  if (m) novelid = m[1];
163
164
  }
164
165
  var typeText = cells.length > 3 ? cells[3].innerText.trim() : '';
@@ -292,33 +293,28 @@ async function scrapeRank(rankTypeId, channelId) {
292
293
  "",
293
294
  `- 来源:${url}`,
294
295
  `- 抓取时间:${now}`,
296
+ `- 条目数:${totalBooks}`,
295
297
  "",
296
298
  "---",
297
299
  "",
298
300
  ];
299
301
 
300
302
  for (const ch of data.channels) {
301
- lines.push(`## ${ch.name}`, "");
302
- for (let i = 0; i < ch.books.length; i++) {
303
- const b = ch.books[i];
304
- lines.push(`书名:${b.title || ""}`);
305
- lines.push(`作者:${b.author || ""}`);
306
- if (data.layout === 'A') {
307
- // 布局A(表格型):已有丰富字段,直接使用
308
- if (b.type) lines.push(`类型:${b.type}`);
309
- if (b.progress) lines.push(`进度:${b.progress}`);
310
- if (b.words) lines.push(`字数:${b.words}`);
311
- if (b.score) lines.push(`积分:${b.score}`);
312
- if (b.pubtime) lines.push(`发表时间:${b.pubtime}`);
313
- lines.push(`题材:${b.type ? b.type.split('-')[1] || b.type : ""}`);
314
- } else {
315
- // 布局B(交替行型):只有书名/作者,其他留空让详情补采
316
- lines.push(`题材:${ch.name}`);
303
+ for (let i = 0; i < ch.books.length; i++) {
304
+ const b = ch.books[i];
305
+ var genre = '';
306
+ if (data.layout === 'A' && b.type) {
307
+ var parts = b.type.split('-');
308
+ genre = parts[1] || '';
309
+ } else {
310
+ genre = ch.name;
311
+ }
312
+ lines.push(`书名:${b.title || ""}`);
313
+ lines.push(`题材:${genre}`);
314
+ lines.push(`作者:${b.author || ""}`);
315
+ if (b.novelid) lines.push(`作品页:https://www.jjwxc.net/onebook.php?novelid=${b.novelid}`);
316
+ lines.push("");
317
317
  }
318
- if (b.novelid) lines.push(`作品页:https://www.jjwxc.net/onebook.php?novelid=${b.novelid}`);
319
- lines.push("");
320
- }
321
- lines.push("--", "");
322
318
  }
323
319
 
324
320
  return {