feat: handle object instead of str for key-val pair
This commit is contained in:
@@ -283,18 +283,10 @@ export default class Interpreter extends EventEmitter {
|
|||||||
await this.options.serializableCallback(scrapeResults);
|
await this.options.serializableCallback(scrapeResults);
|
||||||
},
|
},
|
||||||
|
|
||||||
scrapeSchema: async (schema: Record<string, string>) => {
|
scrapeSchema: async (schema: Record<string, { selector: string; tag: string }>) => {
|
||||||
await this.ensureScriptsLoaded(page);
|
await this.ensureScriptsLoaded(page);
|
||||||
|
|
||||||
const handleLists = await Promise.all(
|
const scrapeResult = await page.evaluate((schemaObj) => window.scrapeSchema(schemaObj), schema);
|
||||||
Object.values(schema).map((selector) => page.$$(selector)),
|
|
||||||
);
|
|
||||||
|
|
||||||
const namedHandleLists = Object.fromEntries(
|
|
||||||
Object.keys(schema).map((key, i) => [key, handleLists[i]]),
|
|
||||||
);
|
|
||||||
|
|
||||||
const scrapeResult = await page.evaluate((n) => window.scrapeSchema(n), namedHandleLists);
|
|
||||||
await this.options.serializableCallback(scrapeResult);
|
await this.options.serializableCallback(scrapeResult);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user