Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
docs: add playwright + firefox example (#1535)
Andrey Bykov3f6fc924675a
diff --git a/docs/examples/playwright_crawler_firefox.mdx b/docs/examples/playwright_crawler_firefox.mdxnew file mode 100644index 000000000..7d66cb363--- /dev/null+++ b/docs/examples/playwright_crawler_firefox.mdx@@ -0,0 +1,22 @@+---+id: playwright-crawler-firefox+title: Using Firefox browser with Playwright crawler+---++import CodeBlock from '@theme/CodeBlock';+import ApiLink from '@site/src/components/ApiLink';+import PlaywrightFirefoxSource from '!!raw-loader!./playwright_crawler_firefox.ts';++This example demonstrates how to use <ApiLink to="playwright-crawler/class/PlaywrightCrawler">`PlaywrightCrawler`</ApiLink> with headless Firefox browser.++:::tip++To run this example on the Apify Platform, select the `apify/actor-node-playwright-firefox` image for your Dockerfile.++:::++<CodeBlock className="language-js">+ {PlaywrightFirefoxSource}+</CodeBlock>++To see a real-world example of how to use <ApiLink to="playwright-crawler/class/PlaywrightCrawler">`PlaywrightCrawler`</ApiLink> in combination with <ApiLink to="core/class/RequestQueue">`RequestQueue`</ApiLink> to recursively scrape the [Hacker News website](https://news.ycombinator.com) check out the [`Playwright crawler example`](./playwright-crawler).diff --git a/docs/examples/playwright_crawler_firefox.ts b/docs/examples/playwright_crawler_firefox.tsnew file mode 100644index 000000000..cd91b2121--- /dev/null+++ b/docs/examples/playwright_crawler_firefox.ts@@ -0,0 +1,22 @@+import { PlaywrightCrawler } from 'crawlee';+import { firefox } from 'playwright';++// Create an instance of the PlaywrightCrawler class.+const crawler = new PlaywrightCrawler({+ launchContext: {+ // Set the Firefox browser to be used by the crawler.+ // If launcher option is not specified here,+ // default Chromium browser will be used.+ launcher: firefox,+ },+ async requestHandler({ request, page, log }) {+ const pageTitle = await page.title();++ log.info(`URL: ${request.loadedUrl} | Page title: ${pageTitle}`);+ },+});++await crawler.addRequests(['https://example.com']);++// Run the crawler and wait for it to finish.+await crawler.run();diff --git a/website/versioned_docs/version-3.0/examples/playwright_crawler_firefox.mdx b/website/versioned_docs/version-3.0/examples/playwright_crawler_firefox.mdxnew file mode 100644index 000000000..7d66cb363--- /dev/null+++ b/website/versioned_docs/version-3.0/examples/playwright_crawler_firefox.mdx@@ -0,0 +1,22 @@+---+id: playwright-crawler-firefox+title: Using Firefox browser with Playwright crawler+---++import CodeBlock from '@theme/CodeBlock';+import ApiLink from '@site/src/components/ApiLink';+import PlaywrightFirefoxSource from '!!raw-loader!./playwright_crawler_firefox.ts';++This example demonstrates how to use <ApiLink to="playwright-crawler/class/PlaywrightCrawler">`PlaywrightCrawler`</ApiLink> with headless Firefox browser.++:::tip++To run this example on the Apify Platform, select the `apify/actor-node-playwright-firefox` image for your Dockerfile.++:::++<CodeBlock className="language-js">+ {PlaywrightFirefoxSource}+</CodeBlock>++To see a real-world example of how to use <ApiLink to="playwright-crawler/class/PlaywrightCrawler">`PlaywrightCrawler`</ApiLink> in combination with <ApiLink to="core/class/RequestQueue">`RequestQueue`</ApiLink> to recursively scrape the [Hacker News website](https://news.ycombinator.com) check out the [`Playwright crawler example`](./playwright-crawler).diff --git a/website/versioned_docs/version-3.0/examples/playwright_crawler_firefox.ts b/website/versioned_docs/version-3.0/examples/playwright_crawler_firefox.tsnew file mode 100644index 000000000..cd91b2121--- /dev/null+++ b/website/versioned_docs/version-3.0/examples/playwright_crawler_firefox.ts@@ -0,0 +1,22 @@+import { PlaywrightCrawler } from 'crawlee';+import { firefox } from 'playwright';++// Create an instance of the PlaywrightCrawler class.+const crawler = new PlaywrightCrawler({+ launchContext: {+ // Set the Firefox browser to be used by the crawler.+ // If launcher option is not specified here,+ // default Chromium browser will be used.+ launcher: firefox,+ },+ async requestHandler({ request, page, log }) {+ const pageTitle = await page.title();++ log.info(`URL: ${request.loadedUrl} | Page title: ${pageTitle}`);+ },+});++await crawler.addRequests(['https://example.com']);++// Run the crawler and wait for it to finish.+await crawler.run();