@cloud411716/fancy-webnovel 0.2.19 → 0.2.20
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
|
@@ -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
|
|
146
|
-
|
|
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 =
|
|
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 (
|
|
161
|
-
var m = (
|
|
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() : '';
|