Skip to main content
Puppeteer is a Node.js library that provides a high-level API to control headless Chrome or Chromium. It’s essential for scraping modern, JavaScript-driven websites (Single Page Applications). Integrating 2extract.com proxies with Puppeteer requires passing a special --proxy-server argument when launching the browser.

Basic Setup

Here’s how to launch a Puppeteer instance that routes all its traffic through our proxy gateway.
You’ll need puppeteer installed in your project: npm install puppeteer
basic_setup.js
Important: Puppeteer requires you to authenticate on a per-page basis using page.authenticate(). You must call this method for every new page (browser.newPage()) you open.

Real-World Example: Taking a Screenshot of Amazon Search Results

A common use case for Puppeteer is to render a full page with dynamic content and take a screenshot, for example, to monitor product rankings or search results on a major eCommerce site like Amazon. Let’s take a screenshot of the search results for “web scraping books” on amazon.com, making the request appear as if it’s coming from the United States.
amazon_scraper.js
Amazon is a challenging target! They employ sophisticated anti-bot measures. While this script works, you may need to implement more advanced techniques for large-scale scraping, such as rotating User-Agents, handling CAPTCHAs, and mimicking human-like browsing behavior (e.g., random delays, mouse movements).

What This Example Demonstrates

  • Scraping a Real, Complex Website: How to approach a major target like Amazon.
  • Proxy Authentication in Puppeteer: The correct two-step process of setting --proxy-server and using page.authenticate().
  • Dynamic Geo-Targeting: Shows how to change your perceived location by modifying the username.
  • Mimicking a Real User: Demonstrates best practices like setting a realistic viewport and User-Agent to reduce the chance of being detected by anti-bot systems.
  • Error Handling: Includes a try...catch block and saves the page’s HTML on failure, which is a crucial technique for debugging scraping issues.