Advertisement
dereksir

Untitled

Feb 28th, 2024 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // import the 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. async function scraper() {
  7.  
  8.     // define your proxy details
  9.     const proxyString = `167.99.174.59:80`;
  10.    
  11.     // set the browser options
  12.     const options = new firefox.Options().addArguments('--headless');
  13.  
  14.     // initialize the webdriver
  15.     const driver = new Builder()
  16.         .forBrowser('firefox')
  17.         // add the proxy to the webdriver
  18.         .setProxy(proxy.manual({
  19.             http: proxyString,
  20.             https: proxyString,
  21.         }))
  22.         .setFirefoxOptions(options)
  23.         .build();
  24.    
  25.     try {
  26.        
  27.         // navigate to target website
  28.         await driver.get('https://httpbin.io/ip');
  29.  
  30.         await driver.sleep(8000);
  31.  
  32.         // get the page text content
  33.         const pageText = await driver.findElement(By.tagName('body')).getText();
  34.         console.log(pageText);
  35.     } catch (error) {
  36.         console.error('An error occurred:', error);
  37.     } finally {
  38.         await driver.quit();
  39.     }
  40. }
  41.  
  42. scraper();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement