Advertisement
dereksir

Untitled

Mar 24th, 2024
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. // import the required libraries
  2. using OpenQA.Selenium;
  3. using OpenQA.Selenium.Chrome;
  4.  
  5. public class Example
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         // set ChromeOptions to run in headless mode
  10.         ChromeOptions options = new ChromeOptions();
  11.         options.AddArgument("--headless");
  12.  
  13.         // set up ChromeDriver
  14.         IWebDriver driver = new ChromeDriver(options);
  15.  
  16.         // navigate to the target url
  17.         string target_url = "https://scrapeme.live/shop/Pikachu/";
  18.         driver.Navigate().GoToUrl(target_url);
  19.  
  20.         // find the element containing the product price
  21.         IWebElement priceElement = driver.FindElement(By.CssSelector("#product-752 > div.summary.entry-summary > p.price > span"));
  22.  
  23.         // extract the text of the product price
  24.         string productPrice = priceElement.Text;
  25.  
  26.         // print the extracted product price
  27.         Console.WriteLine("Product Price: " + productPrice);
  28.  
  29.         // close the browser
  30.         driver.Quit();
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement