Integrating ZenRows Scraping Browser with Puppeteer
The ZenRows® Scraping Browser is a fully managed, out-of-the-box scraping solution designed to simplify the web scraping process. It seamlessly integrates with Puppeteer and allows you to scrape websites using our powerful infrastructure and rotating residential IP pool of over 55 million IPs from 190+ countries, all while maintaining a 99.9% uptime.
This guide will show you how to integrate ZenRows Scraping Browser into your Puppeteer script with just one line of code, providing a fast and easy way to enhance your scraping capabilities.
Installing the required libraries
Puppeteer-Core is a lightweight version of the Puppeteer library explicitly designed to connect to an existing browser instance instead of launching a new one.
You can install puppeteer-core
by running:
If you want to use the ZenRows Browser SDK, install it as well:
Quick Integration with ZenRows Scraping Browser
Without the SDK
If you already have a Puppeteer setup running smoothly, integrating with ZenRows Scraping Browser is incredibly simple. For example, if your Puppeteer code looked like this:
All you need to do is modify one line and swap the launch()
method with the connection URL of the ZenRows Scraping Browser. With just that change, you get the same functionality but with the power of ZenRows’ infrastructure behind it. Here’s the updated code:
And that’s it! With just a single change, you’re now using ZenRows Scraping Browser, which is fully equipped with the scalability, IP rotation, and global access that comes with our service.
With the SDK
ZenRows offers an SDK to make the integration even more seamless. Here’s how to use the SDK for Puppeteer integration:
The SDK handles API key management and makes the connection seamless with fewer manual steps.
Practical Use Cases
Here are some common Puppeteer operations integrated with ZenRows Scraping Browser:
Navigation and Page Content Extraction
Navigate to a webpage, extract the content, and scrape data:
Taking a Screenshot
Capture screenshots during navigation:
Running Custom Code
Execute custom JavaScript code in the browser:
Troubleshooting
Here are some common issues you may encounter when using the Scraping Browser:
Connection Refused
If you encounter a Connection Refused
error when attempting to connect to the Scraping Browser, it’s likely due to:
- API Key Issues: Ensure that you’re using the correct API key.
- Network Issues: Check your internet connection and firewall settings.
- WebSocket Endpoint: Make sure you’re connecting to the correct WebSocket URL (wss://browser.zenrows.com).
Timeout Errors
If Puppeteer times out when trying to load a page, consider:
- Slow Websites: Increase the timeout value in Puppeteer by passing a timeout option:
- Blocked IP: Though ZenRows rotates IPs, some websites may block them. If that happens, try adjusting the region or country.
Frequently Asked Questions (FAQ)
Was this page helpful?