Installing Axios
First, make sure you have Node.js installed. Then, navigate to your project directory and install Axios usingnpm by running:
HTTP client for Node.js, and add it to your project.
Making Requests with ZenRows Residential Proxies
Follow the steps below to use ZenRows Residential Proxies with Node.jsaxios library.
1
Get Your Credentials
Navigate to the ZenRows Residential Proxy Generator Page to get your username, password, and proxy domain.
2
Configure the Proxy URL
If necessary, configure your proxy URL on the Generator Page following the guide on Residential Proxies Setup. Your proxy URL should be in this format:Replace
<YOUR_USERNAME> and <YOUR_PASSWORD> with your ZenRows proxy credentials.3
Code Example
Here’s an example of sending a request through ZenRows Residential Proxies to Expected output:
httpbin.io/ip, which returns the IP address used for the request.scraper.js
Troubleshooting
Here are some common issues you may encounter when using ZenRows Residential Proxies with Node.jsaxios.
Invalid Proxy Credentials
If you encounter a407 Proxy Authentication Required or a 401 Unauthorized error, double-check your username and password in the auth section of your proxy configuration. Ensure that they match the credentials in the ZenRows dashboard.
Axios Version
You’re likely to encounter errors if your Axios version is outdated. Ensure you’re using a recent version of Axios that supports your proxy configuration. Older versions may have bugs or lack features for specific proxy setups. To ensure you install the latest version, run the following installation command:Connection Refused or Blocked
If your requests are being blocked or refused, ensure:- You are correctly matching the protocol (http or https) and port (1337 or 1338).
- The website you’re targeting is not actively blocking you. Some websites employ advanced anti-bot measures that detect proxies.
Invalid Proxy URL Format
Ensure the proxy URL format is correct. It should follow the structure:IP Rotation Settings
If you’re not seeing your IP change as expected, check your Sticky TTL settings on ZenRows. If the Sticky TTL is too long, the same IP will be used for multiple requests. Reduce the Sticky TTL to rotate IPs more frequently.Frequently Asked Questions (FAQs)
Can I use HTTPS with ZenRows® Residential Proxies?
Can I use HTTPS with ZenRows® Residential Proxies?
Yes, ZenRows Residential Proxies support both HTTP and HTTPS. In Axios, you just need to specify the appropriate protocol in the
proxy.host value or use an HTTPS URL.How can I change the IP rotation interval?
How can I change the IP rotation interval?
ZenRows automatically rotates IPs for each request unless you configure a Sticky TTL to keep the same IP for a specific period. This helps in scenarios where maintaining the same IP for a session is required.
What should I do if my requests are blocked?
What should I do if my requests are blocked?
Many websites employ advanced anti-bot measures, such as CAPTCHAs and Web Application Firewalls (WAFs), to prevent automated scraping. Simply using proxies may not be enough to bypass these protections.Instead of relying solely on proxies, consider using ZenRows’ Universal Scraper API, which provides:
- JavaScript Rendering and Interaction Simulation: Optimized with anti-bot bypass capabilities.
- Comprehensive Anti-Bot Toolkit: ZenRows offers advanced tools to overcome complex anti-scraping solutions.
What is the Sticky TTL?
What is the Sticky TTL?
The Sticky TTL (Time To Live) feature allows you to maintain the same IP address for a specified duration, from 30 seconds up to 24 hours. If you don’t set a Sticky TTL, ZenRows will rotate the IP with every request.
How do I know if my proxy is working?
How do I know if my proxy is working?
You can test if the proxy is working by sending a request to
https://httpbin.io/ip. The proxy is successfully applied if the response shows an IP address different from your local IP.