How to extract html links from html file in C#?

前端 未结 3 1686
耶瑟儿~
耶瑟儿~ 2020-12-21 05:52

Can anyone help me by explaining how to extract urls/links from HTML File in C#

3条回答
  •  鱼传尺愫
    2020-12-21 06:20

    look at Html Agility Pack

    HtmlDocument doc = new HtmlDocument(); 
    doc.Load("file.htm");  
    foreach(HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]")) 
    {
        HtmlAttribute att = link.Attributes["href"];
        yourList.Add(att.Value)  
    }  
    doc.Save("file.htm");
    

提交回复
热议问题