Advertisement
dereksir

Untitled

Feb 28th, 2024 (edited)
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // import required libraries
  2. const { Builder, By } = require('selenium-webdriver');
  3. const firefox = require('selenium-webdriver/firefox');
  4. const proxy = require('selenium-webdriver/proxy');
  5.  
  6. // list of proxies
  7. const proxyPool = [
  8.     '136.244.99.51:8888',
  9.     '45.11.95.166:6012',
  10.     '110.34.3.229:3128',
  11.     // add more proxies as needed
  12. ];
  13.  
  14. async function scraper() {
  15.     // select a proxy from the pool
  16.     const selectedProxy = proxyPool[Math.floor(Math.random() * proxyPool.length)];
  17.  
  18.     // set browser options
  19.     const options = new firefox.Options().addArguments('--headless');
  20.  
  21.     // initialize the webdriver
  22.     const driver = new Builder()
  23.         .forBrowser('firefox')
  24.         // add the proxy to the webdriver
  25.         .setProxy(proxy.manual({
  26.             http: selectedProxy,
  27.             https: selectedProxy,
  28.         }))
  29.         .setFirefoxOptions(options)
  30.         .build();
  31.  
  32.     try {        
  33.         // navigate to target website
  34.         await driver.get('https://httpbin.io/ip');
  35.  
  36.         await driver.sleep(8000);
  37.  
  38.         // get the page text content
  39.         const pageText = await driver.findElement(By.css('body')).getText();
  40.         console.log(pageText);
  41.     } catch (error) {
  42.         console.error('An error occurred:', error);
  43.     } finally {
  44.         await driver.quit();
  45.     }
  46. }
  47.  
  48. scraper();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement