Coding Global Background
Coding Global

Web scraper

Archiviert 2 years ago
2 Nachrichten
1 Mitglieder
Erstellt 2 years ago
Aktualisiert 2 years ago
In Discord öffnen
C
cshavoc_28112
using System;
using HtmlAgilityPack;

class Program
{
    static void Main(string[] args)
    {
        // URL of the Pokemon page
        Console.Write("Enter pokemon name: ");
        string pokemonName = Console.ReadLine();
        string url = $"https://www.pokemon.com/uk/pokedex/{pokemonName}";

        // Send HTTP request and get the HTML content
        var web = new HtmlWeb();
        var doc = web.Load(url);

        // Find the element with class="version-x active"
        var descriptionElement = doc.DocumentNode.SelectSingleNode("//p[contains(@class, 'version-x') and contains(@class, 'active')]");

        if (descriptionElement != null)
        {
            // Extract and print the text content of the element
            string description = descriptionElement.InnerText.Trim();
            Console.WriteLine(description);
            Console.ReadLine();
        }
        else
        {
            Console.WriteLine("Description not found.");
            Console.ReadLine();
        }
    }
}



why does it not work?

Antworten (2)