Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using AngleSharp;
- class Scraper
- {
- static async Task Main()
- {
- //..
- {
- //..
- // Query all li within the <ul> with class 'products'
- var Pokemons = document.QuerySelectorAll(".products li");
- // Check if any lists exist
- if (Pokemons != null)
- {
- // Iterate through each li
- foreach (var pokemon in Pokemons)
- {
- // Extract Pokémon information: name, price, and image
- string name = pokemon.QuerySelector("h2")?.TextContent ?? "Name not available";
- string price = pokemon.QuerySelector(".price")?.TextContent ?? "Price not available";
- string image = pokemon.QuerySelector("img")?.GetAttribute("src") ?? "Image not available";
- Console.WriteLine($"Pokémon Name: {name}");
- Console.WriteLine($"Pokémon Price: {price}");
- Console.WriteLine($"Pokémon Image: {image}");
- Console.WriteLine(new string('-', 30)); // Separator for better readability
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement