chore: lint

This commit is contained in:
karishmas6
2024-08-13 22:21:17 +05:30
parent 5874f297b1
commit 00d32571fb

View File

@@ -278,7 +278,7 @@ async function scrollDownToLoadMore(selector, limit) {
* @param {boolean} [config.flexible=false] - Whether to use flexible matching for field selectors * @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 * @returns {Array.<Array.<Object>>} Array of arrays of scraped items, one sub-array per list
*/ */
window.scrapeList = function({ listSelector, fields }) { window.scrapeList = function ({ listSelector, fields }) {
// Get all parent elements matching the listSelector // Get all parent elements matching the listSelector
const parentElements = Array.from(document.querySelectorAll(listSelector)); const parentElements = Array.from(document.querySelectorAll(listSelector));
@@ -286,32 +286,32 @@ async function scrollDownToLoadMore(selector, limit) {
// Iterate through each parent element // Iterate through each parent element
parentElements.forEach(parent => { parentElements.forEach(parent => {
const record = {}; const record = {};
// For each field, select the corresponding element within the parent // For each field, select the corresponding element within the parent
for (const [label, { selector, attribute }] of Object.entries(fields)) { for (const [label, { selector, attribute }] of Object.entries(fields)) {
const fieldElement = parent.querySelector(selector); const fieldElement = parent.querySelector(selector);
// Depending on the attribute specified, extract the data // Depending on the attribute specified, extract the data
if (fieldElement) { if (fieldElement) {
if (attribute === 'innerText') { if (attribute === 'innerText') {
record[label] = fieldElement.innerText.trim(); record[label] = fieldElement.innerText.trim();
} else if (attribute === 'innerHTML') { } else if (attribute === 'innerHTML') {
record[label] = fieldElement.innerHTML.trim(); record[label] = fieldElement.innerHTML.trim();
} else if (attribute === 'src') { } else if (attribute === 'src') {
record[label] = fieldElement.src; record[label] = fieldElement.src;
} else if (attribute === 'href') { } else if (attribute === 'href') {
record[label] = fieldElement.href; record[label] = fieldElement.href;
} else { } else {
// Default to attribute retrieval // Default to attribute retrieval
record[label] = fieldElement.getAttribute(attribute); record[label] = fieldElement.getAttribute(attribute);
} }
}
} }
scrapedData.push(record); }
scrapedData.push(record);
}); });
return scrapedData; return scrapedData;
}; };
/** /**
* Gets all children of the elements matching the listSelector, * Gets all children of the elements matching the listSelector,
@@ -358,5 +358,4 @@ async function scrollDownToLoadMore(selector, limit) {
return results; return results;
}; };
})(window); })(window);