Advertisement
dereksir

Untitled

Nov 27th, 2023 (edited)
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using AngleSharp;
  2.  
  3. class Scraper
  4. {
  5.     static async Task Main()
  6.     {
  7.        //..
  8.         {
  9.             //..
  10.  
  11.             // Query all li within the <ul> with class 'products'
  12.             var Pokemons = document.QuerySelectorAll(".products li");
  13.  
  14.             // Check if any lists exist
  15.             if (Pokemons != null)
  16.             {
  17.                 // Iterate through each li
  18.                 foreach (var pokemon in Pokemons)
  19.                 {
  20.                     // Extract Pokémon information: name, price, and image
  21.                     string name = pokemon.QuerySelector("h2")?.TextContent ?? "Name not available";
  22.                     string price = pokemon.QuerySelector(".price")?.TextContent ?? "Price not available";
  23.                     string image = pokemon.QuerySelector("img")?.GetAttribute("src") ?? "Image not available";
  24.  
  25.                     Console.WriteLine($"Pokémon Name: {name}");
  26.                     Console.WriteLine($"Pokémon Price: {price}");
  27.                     Console.WriteLine($"Pokémon Image: {image}");
  28.                     Console.WriteLine(new string('-', 30)); // Separator for better readability
  29.                 }
  30.             }  
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement