feat: add scrapeSchema data accumulation logic
This commit is contained in:
@@ -329,12 +329,20 @@ export default class Interpreter extends EventEmitter {
|
||||
scrapeSchema: async (schema: Record<string, { selector: string; tag: string, attribute: string; }>) => {
|
||||
await this.ensureScriptsLoaded(page);
|
||||
|
||||
// Scrape data using the schema
|
||||
const scrapeResult = await page.evaluate((schemaObj) => window.scrapeSchema(schemaObj), schema);
|
||||
|
||||
// Log result and accumulate it
|
||||
console.log("Scrape result:", scrapeResult);
|
||||
this.cumulativeResults.push(...(Array.isArray(scrapeResult) ? scrapeResult : [scrapeResult]));
|
||||
const newResults = Array.isArray(scrapeResult) ? scrapeResult : [scrapeResult];
|
||||
newResults.forEach((result) => {
|
||||
Object.entries(result).forEach(([key, value]) => {
|
||||
const keyExists = this.cumulativeResults.some(
|
||||
(item) => key in item && item[key] !== undefined
|
||||
);
|
||||
|
||||
if (!keyExists) {
|
||||
this.cumulativeResults.push({ [key]: value });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const mergedResult: Record<string, string>[] = [
|
||||
Object.fromEntries(
|
||||
|
||||
Reference in New Issue
Block a user