Advertisement
dereksir

Untitled

Mar 24th, 2024 (edited)
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. // import the required package
  2. using PuppeteerSharp;
  3.  
  4. class Program
  5. {
  6.     static async Task Main(string[] args)
  7.     {
  8.         using var browserFetcher = new BrowserFetcher();
  9.         await browserFetcher.DownloadAsync();
  10.  
  11.         // launch a new headless browser instance
  12.         await using var browser = await Puppeteer.LaunchAsync(
  13.             new LaunchOptions { Headless = true });
  14.        
  15.         // open a new browser page
  16.         await using var page = await browser.NewPageAsync();
  17.  
  18.         // navigate to target website
  19.         await page.GoToAsync("https://scrapeme.live/shop/Pikachu/");
  20.  
  21.         // extract product price
  22.         var productPrice = await page.EvaluateExpressionAsync<string>(
  23.             "document.querySelector('#product-752 > div.summary.entry-summary > p.price > span').innerText");
  24.  
  25.         // print the product price
  26.         Console.WriteLine("Product Price: " + productPrice);
  27.  
  28.         // close the browser when done
  29.         await browser.CloseAsync();
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement