refactor: add facebook bootstrap candidate extraction
This commit is contained in:
@@ -408,6 +408,30 @@ export function classifyFacebookResponse(
|
||||
return { kind: "unknown" as const, authGated: false, unavailable: false };
|
||||
}
|
||||
|
||||
export function extractFacebookBootstrapCandidates(
|
||||
htmlString: HTMLString,
|
||||
): Record<string, unknown>[] {
|
||||
const { document } = parseHTML(htmlString);
|
||||
const scripts = document.querySelectorAll("script");
|
||||
const candidates: Record<string, unknown>[] = [];
|
||||
|
||||
for (const script of Array.from(scripts) as HTMLScriptElement[]) {
|
||||
const scriptText = script.textContent?.trim();
|
||||
if (!scriptText) continue;
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(scriptText);
|
||||
if (isRecord(parsed)) {
|
||||
candidates.push(parsed as Record<string, unknown>);
|
||||
}
|
||||
} catch {
|
||||
// skip non-JSON script bodies
|
||||
}
|
||||
}
|
||||
|
||||
return candidates;
|
||||
}
|
||||
|
||||
/**
|
||||
Extract marketplace search data from Facebook page script tags
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user