Advertisement
dereksir

Untitled

Aug 31st, 2023 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { chromium } = require('playwright-extra');
  2. const ProxyRouter = require('@extra/proxy-router');
  3.  
  4. // Configure the proxy router plugin
  5. const proxyRouter = ProxyRouter({
  6.   proxies: {
  7.     DEFAULT: 'http://user:pass@proxyhost1:port1',
  8.     PROXY2: 'http://user:pass@proxyhost2:port2',
  9.     PROXY3: 'http://user:pass@proxyhost3:port3',
  10.     // Define more proxies as needed
  11.   },
  12. });
  13.  
  14. // Add the plugin
  15. chromium.use(proxyRouter);
  16.  
  17. (async () => {
  18.     const browser = await chromium.launch({ headless: true });
  19.  
  20.     // Define target URL
  21.     const url = 'http://httpbin.io/ip';
  22.     // List of proxies to use
  23.     const proxyNames = ['DEFAULT', 'PROXY2', 'PROXY3'];
  24.  
  25.     // Loop through each proxy
  26.     for (const proxyName of proxyNames) {
  27.         const page = await browser.newPage();
  28.  
  29.         // Use the current proxy for the page
  30.         await page.routeByProxy(proxyName);
  31.  
  32.         // Navigate to the target page
  33.         await page.goto(url, { waitUntil: 'domcontentloaded' });
  34.  
  35.         // Get the text content of the page
  36.         const textContent = await page.evaluate(() => document.body.textContent);
  37.  
  38.         console.log('IP:');
  39.         console.log(textContent);
  40.  
  41.         // Close the page for the next iteration
  42.         await page.close();
  43.   }
  44.  
  45.     await browser.close();
  46. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement