feat: revert non-table scraping logic
This commit is contained in:
@@ -437,26 +437,19 @@ function scrapableHeuristics(maxCountPerPage = 50, minArea = 20000, scrolls = 3,
|
|||||||
|
|
||||||
// Handle non-table fields
|
// Handle non-table fields
|
||||||
if (Object.keys(nonTableFields).length > 0) {
|
if (Object.keys(nonTableFields).length > 0) {
|
||||||
const firstField = Object.values(nonTableFields)[0];
|
const record = {};
|
||||||
const baseElements = Array.from(container.querySelectorAll(firstField.selector));
|
|
||||||
|
|
||||||
for (let i = 0; i < Math.min(baseElements.length, limit); i++) {
|
for (const [label, { selector, attribute }] of Object.entries(nonTableFields)) {
|
||||||
const record = {};
|
const element = container.querySelector(selector);
|
||||||
|
|
||||||
for (const [label, { selector, attribute }] of Object.entries(nonTableFields)) {
|
if (element) {
|
||||||
const elements = Array.from(parent.querySelectorAll(selector));
|
record[label] = extractValue(element, attribute);
|
||||||
// Use the same index to maintain correspondence between fields
|
|
||||||
const element = elements[i];
|
|
||||||
|
|
||||||
if (element) {
|
|
||||||
record[label] = extractValue(element, attribute);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.keys(record).length > 0) {
|
|
||||||
scrapedData.push(record);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(record).length > 0) {
|
||||||
|
scrapedData.push(record);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user