--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 puppeteerbasic_setup.js
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” onamazon.com, making the request appear as if it’s coming from the United States.
amazon_scraper.js
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-serverand usingpage.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-Agentto reduce the chance of being detected by anti-bot systems. - Error Handling: Includes a
try...catchblock and saves the page’s HTML on failure, which is a crucial technique for debugging scraping issues.