Advertisement
dereksir

Untitled

Mar 29th, 2024 (edited)
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.23 KB | None | 0 0
  1. package com.example;
  2.  
  3. // import the required dependencies
  4. import org.openqa.selenium.*;
  5. import org.openqa.selenium.chrome.*;
  6. import com.jauntium.*;
  7.  
  8. public class Main {
  9.     public static void main(String[] args) {
  10.         // use WebDriver manager to set up ChromeDriver
  11.         WebDriverManager.chromedriver().setup();
  12.  
  13.         // create Chrome options object
  14.         ChromeOptions options = new ChromeOptions();
  15.         // specify headless mode              
  16.         options.addArguments("--headless");                        
  17.  
  18.         try {
  19.  
  20.             // create a new browser window
  21.             Browser browser = new Browser(new ChromeDriver(options));  
  22.             // navigate to target URL
  23.             browser.visit("https://scrapeme.live/shop/Pikachu/");                
  24.    
  25.             // extract product price.  
  26.             Element priceElement = browser.doc.findFirst("<p class=price>");
  27.             String price = priceElement.getText();  
  28.             System.out.println("Product Price: " + price);
  29.    
  30.             browser.quit();  
  31.         }
  32.         // if element isn't found, handle JauntiumException.
  33.         catch(JauntiumException e){  
  34.             System.err.println(e);
  35.         }            
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement