feat: extract window.context.result.data for structured logistics data
register-skill-release / register (push) Successful in 13s
Details
register-skill-release / register (push) Successful in 13s
Details
Poll window.context.result.data (up to 15s) for productPackInfo, productTitle, productAttributes, and skuSelection. This provides structured weight/size/volume data per-variant directly from 1688's JS context — more reliable than vision-only extraction. Screenshots still captured as fallback for data only in images. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
93517505d4
commit
935cac3c61
37
src/index.ts
37
src/index.ts
|
|
@ -9,6 +9,8 @@ export interface ScrapeResult {
|
||||||
command: Command;
|
command: Command;
|
||||||
dryRun: boolean;
|
dryRun: boolean;
|
||||||
offerId: string;
|
offerId: string;
|
||||||
|
productPackInfo?: unknown;
|
||||||
|
windowContext?: unknown;
|
||||||
screenshots?: string[];
|
screenshots?: string[];
|
||||||
detailImages?: string[];
|
detailImages?: string[];
|
||||||
error?: string;
|
error?: string;
|
||||||
|
|
@ -202,8 +204,37 @@ export async function run(
|
||||||
|
|
||||||
await cdp.send('Page.navigate', { url });
|
await cdp.send('Page.navigate', { url });
|
||||||
|
|
||||||
// Wait for page load + dynamic content
|
// Wait for window.context.result.data to be populated (poll up to 15s)
|
||||||
await new Promise(r => setTimeout(r, 5000));
|
let productPackInfo: unknown = null;
|
||||||
|
let windowContext: unknown = null;
|
||||||
|
for (let i = 0; i < 30; i++) {
|
||||||
|
await new Promise(r => setTimeout(r, 500));
|
||||||
|
const ctx = await cdp.evaluate(`
|
||||||
|
(function() {
|
||||||
|
try {
|
||||||
|
const d = window.context && window.context.result && window.context.result.data;
|
||||||
|
if (d && d.productPackInfo) {
|
||||||
|
return JSON.stringify({
|
||||||
|
productPackInfo: d.productPackInfo,
|
||||||
|
productTitle: d.productTitle || null,
|
||||||
|
productAttributes: d.productAttributes || null,
|
||||||
|
skuSelection: d.skuSelection || null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
return null;
|
||||||
|
})()
|
||||||
|
`);
|
||||||
|
if (ctx) {
|
||||||
|
const parsed = JSON.parse(ctx);
|
||||||
|
productPackInfo = parsed.productPackInfo;
|
||||||
|
windowContext = parsed;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extra wait for remaining dynamic content (images etc)
|
||||||
|
await new Promise(r => setTimeout(r, 2000));
|
||||||
|
|
||||||
const outputDir = path.join('/tmp', '1688-logistics', offerId);
|
const outputDir = path.join('/tmp', '1688-logistics', offerId);
|
||||||
|
|
||||||
|
|
@ -217,6 +248,8 @@ export async function run(
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: 'success', url, command, dryRun, offerId,
|
status: 'success', url, command, dryRun, offerId,
|
||||||
|
productPackInfo,
|
||||||
|
windowContext,
|
||||||
screenshots,
|
screenshots,
|
||||||
detailImages,
|
detailImages,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue