Extract all a `href`s from webpage with htmlagilitypack/requests anything

后端 未结 1 1446
终归单人心
终归单人心 2021-01-26 06:33

I have this web page source:

\"\"

        
相关标签:
1条回答
  • 2021-01-26 07:24

    It should be quite simple to get what you need with the HtmlAgilityPack. Assuming you have your document loaded into an HtmlDocument object named doc:

    HtmlNodeCollection collection = doc.DocumentNode.SelectNodes("//a[@href]");
    
    foreach (HtmlNode node in collection)
    {
        // Do what you want with the href value in here. As an example, this just
        //  just prints the value to the console.
        Console.WriteLine(node.GetAttributeValue("href", "default"));
    }
    
    0 讨论(0)
提交回复
热议问题