Advertisement
dereksir

Untitled

Feb 28th, 2024 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Builder, By } =  require('selenium-webdriver');
  2. const firefox = require('selenium-webdriver/firefox');
  3.  
  4. async function scraper() {
  5.    
  6.     // set the browser options
  7.     const options = new firefox.Options().addArguments('--headless');
  8.  
  9.     // initialize the webdriver
  10.     const driver = new Builder()
  11.      .forBrowser('firefox')
  12.      .setFirefoxOptions(options)
  13.      .build();
  14.    
  15.      try {
  16.        
  17.         // navigate to target website
  18.         await driver.get('https://httpbin.io/ip');
  19.  
  20.         // get the page text content
  21.         const pageText = await driver.findElement(By.css('body')).getText();
  22.         console.log(pageText);
  23.      } catch (error) {
  24.         console.error('An error occurred:', error);
  25.  
  26.      } finally{
  27.        await driver.quit();
  28.      
  29.      }
  30.  
  31.  }
  32.  
  33. scraper();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement