Regular expression for parsing links from a webpage?

前端 未结 9 717
南旧
南旧 2020-11-27 20:02

I\'m looking for a .NET regular expression extract all the URLs from a webpage but haven\'t found one to be comprehensive enough to cover all the different ways you can spec

9条回答
  •  旧巷少年郎
    2020-11-27 20:50

    With Html Agility Pack, you can use:

    HtmlDocument doc = new HtmlDocument();
    doc.Load("file.htm");
    foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a@href")
    {
    Response.Write(link["href"].Value);
    }
    doc.Save("file.htm");
    

提交回复
热议问题