Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fetch from 'node-fetch';
- import { HttpsProxyAgent } from 'https-proxy-agent';
- const proxyList = [
- { host: '103.69.108.78', port: 8191 },
- { host: '61.29.96.146', port: 80 },
- { host: '154.204.58.155', port: 8090 },
- ];
- async function RotateProxy(proxyList, targetUrl) {
- for (const proxy of proxyList) {
- try {
- //construct proxy URL
- const proxyUrl = `http://${proxy.host}:${proxy.port}`;
- //create proxy agent
- const proxyAgent = new HttpsProxyAgent(proxyUrl);
- //make request using random proxy from array
- const response = await fetch(targetUrl, { agent: proxyAgent });
- const html = await response.text();
- //request status code
- const statusCode = response.status;
- console.log('Status Code:', statusCode);
- console.log(html);
- } catch (error) {
- console.error(error);
- }
- }
- }
- const targetUrl = 'https://www.amazon.com/Bose-QuietComfort-45-Bluetooth-Canceling-Headphones/dp/B098FKXT8L?th=1';
- await RotateProxy(proxyList, targetUrl);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement