Send Axios requests through a rotating proxy agent.
Send Axios requests through a rotating proxy agent. This example uses Rotating Proxies as the default gateway and can be adapted by replacing endpoint and routing credentials.
Install the client and create a file.
Use a clean project environment and pin tested dependency versions for production. The example target is a public scraping sandbox.
npm install axios https-proxy-agent cheerioLoad proxy secrets from the environment.
The proxy username is not the LundProxy website login. Copy the complete username and password generated for the selected proxy product.
PROXY_USER=user-pool-crawlerPROXY_PASS=your-secretscrape.mjs
Copy the code into the named file, set credentials, and run it from the project environment.
import axios from "axios";
import * as cheerio from "cheerio";
import { HttpsProxyAgent } from "https-proxy-agent";
const proxyUrl =
"http://" +
encodeURIComponent(process.env.PROXY_USER) + ":" +
encodeURIComponent(process.env.PROXY_PASS) +
"@proxy.lundproxy.com:36923";
const response = await axios.get("https://quotes.toscrape.com/", {
httpsAgent: new HttpsProxyAgent(proxyUrl),
proxy: false,
timeout: 30_000,
validateStatus: status => status >= 200 && status < 400,
});
const $ = cheerio.load(response.data);
console.log($(".quote").length);
Keep the important behavior visible.
Add workload-specific controls before scale.
Test representative targets, response sizes, routing policy, concurrency, retries, validation, and completion window. Collect only public data you are authorized to access.
Axios questions.
Why set proxy to false?
It prevents Axios from applying a second proxy configuration on top of the custom agent.
Can one agent be reused?
Yes. Reuse a configured agent for matching route policy and connection behavior.
Where should retries be added?
Wrap idempotent requests with a bounded backoff policy that records attempt reasons.