Advertisement
dereksir

Untitled

May 12th, 2023 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import fetch from 'node-fetch';
  2. import { HttpsProxyAgent } from 'https-proxy-agent';
  3.  
  4. const proxyList = [
  5.   { host: '103.69.108.78', port: 8191 },
  6.   { host: '61.29.96.146', port: 80 },
  7.   { host: '154.204.58.155', port: 8090 },
  8. ];
  9.  
  10. async function RotateProxy(proxyList, targetUrl) {
  11.   for (const proxy of proxyList) {
  12.     try {
  13.       //construct proxy URL  
  14.       const proxyUrl = `http://${proxy.host}:${proxy.port}`;
  15.       //create proxy agent  
  16.       const proxyAgent = new HttpsProxyAgent(proxyUrl);
  17.  
  18.       //make request using random proxy from array  
  19.       const response = await fetch(targetUrl, { agent: proxyAgent });
  20.       const html = await response.text();
  21.      
  22.       //request status code
  23.       const statusCode = response.status;
  24.  
  25.       console.log('Status Code:', statusCode);
  26.       console.log(html);
  27.     } catch (error) {
  28.       console.error(error);
  29.     }
  30.   }
  31. }
  32.  
  33. const targetUrl = 'https://www.amazon.com/Bose-QuietComfort-45-Bluetooth-Canceling-Headphones/dp/B098FKXT8L?th=1';
  34. await RotateProxy(proxyList, targetUrl);
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement