maxun-core 0.0.30 → 0.0.31
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/build/interpret.js +42 -6
- package/package.json +1 -1
package/build/interpret.js
CHANGED
|
@@ -1496,8 +1496,17 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
1496
1496
|
scrapedItems.add(uniqueKey);
|
|
1497
1497
|
return true;
|
|
1498
1498
|
});
|
|
1499
|
-
|
|
1500
|
-
|
|
1499
|
+
let itemsToAdd = newResults;
|
|
1500
|
+
if (config.limit) {
|
|
1501
|
+
const remainingCapacity = config.limit - allResults.length;
|
|
1502
|
+
if (remainingCapacity <= 0) {
|
|
1503
|
+
itemsToAdd = [];
|
|
1504
|
+
}
|
|
1505
|
+
else if (newResults.length > remainingCapacity) {
|
|
1506
|
+
itemsToAdd = newResults.slice(0, remainingCapacity);
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
allResults = allResults.concat(itemsToAdd);
|
|
1501
1510
|
this.serializableDataByType[actionType][actionName] = [...allResults];
|
|
1502
1511
|
yield this.options.serializableCallback({
|
|
1503
1512
|
scrapeList: this.serializableDataByType.scrapeList,
|
|
@@ -1635,11 +1644,38 @@ class Interpreter extends events_1.EventEmitter {
|
|
|
1635
1644
|
if (checkLimit()) {
|
|
1636
1645
|
return allResults;
|
|
1637
1646
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1647
|
+
const scrollIterations = 3;
|
|
1648
|
+
for (let i = 0; i < scrollIterations; i++) {
|
|
1649
|
+
yield page.evaluate(() => {
|
|
1650
|
+
window.scrollBy(0, window.innerHeight * 0.8);
|
|
1651
|
+
});
|
|
1652
|
+
yield page.waitForTimeout(500);
|
|
1653
|
+
}
|
|
1642
1654
|
yield page.waitForTimeout(2000);
|
|
1655
|
+
try {
|
|
1656
|
+
yield page.evaluate((listSelector) => {
|
|
1657
|
+
const isXPath = listSelector.startsWith('//') || listSelector.startsWith('/');
|
|
1658
|
+
let lastElement = null;
|
|
1659
|
+
if (isXPath) {
|
|
1660
|
+
const result = document.evaluate(listSelector, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
|
1661
|
+
if (result.snapshotLength > 0) {
|
|
1662
|
+
lastElement = result.snapshotItem(result.snapshotLength - 1);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
else {
|
|
1666
|
+
const elements = document.querySelectorAll(listSelector);
|
|
1667
|
+
if (elements.length > 0) {
|
|
1668
|
+
lastElement = elements[elements.length - 1];
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
if (lastElement) {
|
|
1672
|
+
lastElement.scrollIntoView({ behavior: 'smooth', block: 'end' });
|
|
1673
|
+
}
|
|
1674
|
+
}, config.listSelector);
|
|
1675
|
+
yield page.waitForTimeout(1500);
|
|
1676
|
+
}
|
|
1677
|
+
catch (e) {
|
|
1678
|
+
}
|
|
1643
1679
|
const currentHeight = yield page.evaluate(() => {
|
|
1644
1680
|
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
|
|
1645
1681
|
});
|