import { Router } from "crawlee";
export const router = Router.create();
// ... other handlers
// imagine the category handler is called twice
router.addHandler("CATEGORY", async ({ enqueueLinks }) => {
// ... parsing
// result of first call
await enqueueLinks({
urls: ["https://example.com/my-product"],
userData: { category: "foo" },
label: "DETAIL",
});
// result of second call
await enqueueLinks({
urls: ["https://example.com/my-product"],
userData: { category: "bar" },
label: "DETAIL",
});
});
router.addHandler("DETAIL", async ({ request }) => {
// todo: how to get both "foo" and "bar" here?
const category = request.userData.category;
// ... saving
});
import { Router } from "crawlee";
export const router = Router.create();
// ... other handlers
// imagine the category handler is called twice
router.addHandler("CATEGORY", async ({ enqueueLinks }) => {
// ... parsing
// result of first call
await enqueueLinks({
urls: ["https://example.com/my-product"],
userData: { category: "foo" },
label: "DETAIL",
});
// result of second call
await enqueueLinks({
urls: ["https://example.com/my-product"],
userData: { category: "bar" },
label: "DETAIL",
});
});
router.addHandler("DETAIL", async ({ request }) => {
// todo: how to get both "foo" and "bar" here?
const category = request.userData.category;
// ... saving
});