chore: lint
This commit is contained in:
@@ -200,7 +200,7 @@ async function clickNextPagination(selector, scrapedData, limit) {
|
||||
throw new Error("No more items to load or pagination has ended.");
|
||||
}
|
||||
|
||||
//return clicked; // Indicate whether pagination occurred
|
||||
return clicked; // Indicate whether pagination occurred
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ async function clickNextPagination(selector, scrapedData, limit) {
|
||||
* @param {boolean} [config.flexible=false] - Whether to use flexible matching for field selectors
|
||||
* @returns {Array.<Array.<Object>>} Array of arrays of scraped items, one sub-array per list
|
||||
*/
|
||||
window.scrapeList = async function({ listSelector, fields, limit = 10, pagination = null }) {
|
||||
window.scrapeList = async function ({ listSelector, fields, limit = 10, pagination = null }) {
|
||||
const scrapedData = [];
|
||||
|
||||
while (scrapedData.length < limit) {
|
||||
@@ -355,7 +355,6 @@ async function clickNextPagination(selector, scrapedData, limit) {
|
||||
for (const [label, { selector, attribute }] of Object.entries(fields)) {
|
||||
const fieldElement = parent.querySelector(selector);
|
||||
|
||||
// Depending on the attribute specified, extract the data
|
||||
if (fieldElement) {
|
||||
if (attribute === 'innerText') {
|
||||
record[label] = fieldElement.innerText.trim();
|
||||
@@ -366,7 +365,6 @@ async function clickNextPagination(selector, scrapedData, limit) {
|
||||
} else if (attribute === 'href') {
|
||||
record[label] = fieldElement.href;
|
||||
} else {
|
||||
// Default to attribute retrieval
|
||||
record[label] = fieldElement.getAttribute(attribute);
|
||||
}
|
||||
}
|
||||
@@ -376,19 +374,25 @@ async function clickNextPagination(selector, scrapedData, limit) {
|
||||
scrapedData.push(record);
|
||||
}
|
||||
|
||||
// Check if we need to paginate
|
||||
if (pagination && scrapedData.length < limit) {
|
||||
let paginated = false;
|
||||
|
||||
switch (pagination.type) {
|
||||
case 'scrollDown':
|
||||
await scrollDownToLoadMore(listSelector, limit);
|
||||
paginated = true;
|
||||
break;
|
||||
case 'scrollUp':
|
||||
await scrollUpToLoadMore(listSelector, limit);
|
||||
paginated = true;
|
||||
break;
|
||||
case 'clickNext':
|
||||
await clickNextPagination(pagination.selector, scrapedData, limit);
|
||||
paginated = await clickNextPagination(pagination.selector, scrapedData, limit);
|
||||
break;
|
||||
case 'clickLoadMore':
|
||||
//await clickLoadMorePagination(pagination.selector);
|
||||
//paginated = true;
|
||||
break;
|
||||
case 'none':
|
||||
// No more items to load
|
||||
@@ -397,14 +401,19 @@ async function clickNextPagination(selector, scrapedData, limit) {
|
||||
console.warn("Unknown pagination type");
|
||||
break;
|
||||
}
|
||||
|
||||
if (paginated) {
|
||||
await new Promise(resolve => setTimeout(resolve, 2000)); // Wait for content to load
|
||||
} else {
|
||||
break; // No further pagination needed
|
||||
}
|
||||
} else {
|
||||
break; // No more items to load or no pagination
|
||||
}
|
||||
}
|
||||
|
||||
return scrapedData.slice(0, limit); // Return only the limited number of records
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user