mirror of
https://git.mirrors.martin98.com/https://github.com/mendableai/firecrawl
synced 2025-08-04 23:00:40 +08:00
Update single_url.ts
This commit is contained in:
parent
b8266cc329
commit
1da026b26e
@ -6,6 +6,7 @@ import {
|
|||||||
PageOptions,
|
PageOptions,
|
||||||
FireEngineResponse,
|
FireEngineResponse,
|
||||||
ExtractorOptions,
|
ExtractorOptions,
|
||||||
|
Action,
|
||||||
} from "../../lib/entities";
|
} from "../../lib/entities";
|
||||||
import { parseMarkdown } from "../../lib/html-to-markdown";
|
import { parseMarkdown } from "../../lib/html-to-markdown";
|
||||||
import { urlSpecificParams } from "./utils/custom/website_params";
|
import { urlSpecificParams } from "./utils/custom/website_params";
|
||||||
@ -202,6 +203,23 @@ export async function scrapSingleUrl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.FIRE_ENGINE_BETA_URL) {
|
if (process.env.FIRE_ENGINE_BETA_URL) {
|
||||||
|
const processedActions: Action[] = pageOptions.actions?.flatMap((action: Action, index: number, array: Action[]) => {
|
||||||
|
if (action.type === "click" || action.type === "write" || action.type === "press") {
|
||||||
|
const result: Action[] = [];
|
||||||
|
// Don't add a wait if the previous action is a wait
|
||||||
|
if (index === 0 || array[index - 1].type !== "wait") {
|
||||||
|
result.push({ type: "wait", milliseconds: 1200 } as Action);
|
||||||
|
}
|
||||||
|
result.push(action);
|
||||||
|
// Don't add a wait if the next action is a wait
|
||||||
|
if (index === array.length - 1 || array[index + 1].type !== "wait") {
|
||||||
|
result.push({ type: "wait", milliseconds: 1200 } as Action);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return [action as Action];
|
||||||
|
}) ?? [] as Action[];
|
||||||
|
|
||||||
const response = await scrapWithFireEngine({
|
const response = await scrapWithFireEngine({
|
||||||
url,
|
url,
|
||||||
...(engine === "chrome-cdp" ? ({
|
...(engine === "chrome-cdp" ? ({
|
||||||
@ -214,7 +232,7 @@ export async function scrapSingleUrl(
|
|||||||
type: "screenshot" as const,
|
type: "screenshot" as const,
|
||||||
fullPage: !!pageOptions.fullPageScreenshot,
|
fullPage: !!pageOptions.fullPageScreenshot,
|
||||||
}] : []),
|
}] : []),
|
||||||
...(pageOptions.actions ?? []),
|
...processedActions,
|
||||||
],
|
],
|
||||||
}) : ({
|
}) : ({
|
||||||
waitFor: pageOptions.waitFor,
|
waitFor: pageOptions.waitFor,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user