How to use HTML Agility pack

后端 未结 7 1789
闹比i
闹比i 2020-11-21 04:30

How do I use the HTML Agility Pack?

My XHTML document is not completely valid. That\'s why I wanted to use it. How do I use it in my project? My project is in C#.

7条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-21 05:21

        public string HtmlAgi(string url, string key)
        {
    
            var Webget = new HtmlWeb();
            var doc = Webget.Load(url);
            HtmlNode ourNode = doc.DocumentNode.SelectSingleNode(string.Format("//meta[@name='{0}']", key));
    
            if (ourNode != null)
            {
    
    
                    return ourNode.GetAttributeValue("content", "");
    
            }
            else
            {
                return "not fount";
            }
    
        }
    

提交回复
热议问题