Advertisement
dereksir

Untitled

Aug 31st, 2023 (edited)
202
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://217.11.184.20:3128',
  8.     PROXY2: 'http://20.33.5.27:8888',
  9.     PROXY3: 'http://45.133.72.252:3128',
  10.     // Define more proxies as needed
  11.   },
  12. });
  13.  
  14. // Add the plugin
  15. chromium.use(proxyRouter);
  16.  
  17. chromium.launch({ headless: true }).then(async browser => {
  18.  
  19.     // Define target URL
  20.     const url = 'http://httpbin.io/ip';
  21.     // List of proxies to use
  22.     const proxyNames = ['DEFAULT', 'PROXY2', 'PROXY3'];
  23.  
  24.     // Loop through each proxy
  25.     for (const proxyName of proxyNames) {
  26.         const page = await browser.newPage();
  27.  
  28.         // Use the current proxy for the page
  29.         await page.route(url, (route) => {
  30.             route.continue({ server: proxyName });
  31.         });
  32.  
  33.         // Navigate to the target page
  34.         await page.goto(url, { waitUntil: 'domcontentloaded' });
  35.  
  36.         // Get the text content of the page
  37.         const textContent = await page.evaluate(() => document.body.textContent);
  38.  
  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