diff --git a/docs/introduction/05-crawling.mdx b/docs/introduction/05-crawling.mdx index 6621ee10b0ff..a3930c6b6be5 100644 --- a/docs/introduction/05-crawling.mdx +++ b/docs/introduction/05-crawling.mdx @@ -23,16 +23,21 @@ import { PlaywrightCrawler } from 'crawlee'; const crawler = new PlaywrightCrawler({ requestHandler: async ({ page, request, enqueueLinks }) => { console.log(`Processing: ${request.url}`); - // Wait for the category cards to render, - // otherwise enqueueLinks wouldn't enqueue anything. - await page.waitForSelector('.collection-block-item'); - - // Add links to the queue, but only from - // elements matching the provided selector. - await enqueueLinks({ - selector: '.collection-block-item', - label: 'CATEGORY', - }); + + // Only run this logic on the main category listing, not on sub-pages. + if (request.label !== 'CATEGORY') { + + // Wait for the category cards to render, + // otherwise enqueueLinks wouldn't enqueue anything. + await page.waitForSelector('.collection-block-item'); + + // Add links to the queue, but only from + // elements matching the provided selector. + await enqueueLinks({ + selector: '.collection-block-item', + label: 'CATEGORY', + }); + } }, }); diff --git a/website/versioned_docs/version-3.12/introduction/05-crawling.mdx b/website/versioned_docs/version-3.12/introduction/05-crawling.mdx index 6621ee10b0ff..a3930c6b6be5 100644 --- a/website/versioned_docs/version-3.12/introduction/05-crawling.mdx +++ b/website/versioned_docs/version-3.12/introduction/05-crawling.mdx @@ -23,16 +23,21 @@ import { PlaywrightCrawler } from 'crawlee'; const crawler = new PlaywrightCrawler({ requestHandler: async ({ page, request, enqueueLinks }) => { console.log(`Processing: ${request.url}`); - // Wait for the category cards to render, - // otherwise enqueueLinks wouldn't enqueue anything. - await page.waitForSelector('.collection-block-item'); - - // Add links to the queue, but only from - // elements matching the provided selector. - await enqueueLinks({ - selector: '.collection-block-item', - label: 'CATEGORY', - }); + + // Only run this logic on the main category listing, not on sub-pages. + if (request.label !== 'CATEGORY') { + + // Wait for the category cards to render, + // otherwise enqueueLinks wouldn't enqueue anything. + await page.waitForSelector('.collection-block-item'); + + // Add links to the queue, but only from + // elements matching the provided selector. + await enqueueLinks({ + selector: '.collection-block-item', + label: 'CATEGORY', + }); + } }, });