Advertisement
dereksir

Untitled

Mar 24th, 2024
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using Microsoft.Playwright;
  2. using System.Threading.Tasks;
  3.  
  4. class Program
  5. {
  6.     static async Task Main(string[] args)
  7.     {
  8.         // launch Playwright
  9.         using var playwright = await Playwright.CreateAsync();
  10.  
  11.         // launch Chromium browser
  12.         await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true });
  13.  
  14.         // create a new page
  15.         var page = await browser.NewPageAsync();
  16.  
  17.         // navigate to the scrapeme website
  18.         await page.GotoAsync("https://scrapeme.live/shop/Pikachu/");
  19.  
  20.         // extract the product price
  21.         var priceElement = await page.QuerySelectorAsync("#product-752 > div.summary.entry-summary > p.price > span");
  22.         var productPrice = await priceElement.InnerTextAsync();
  23.  
  24.         // print the product price
  25.         Console.WriteLine($"Product Price: {productPrice}");
  26.  
  27.         // close the browser
  28.         await browser.CloseAsync();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement