예제 #1
0
 public static CurseMenuItem TryPrase(string html)
 {
     try
     {
         HtmlDocument doc = new HtmlDocument();
         doc.LoadHtml("<html>" + html + "</html>");
         string title = doc.DocumentNode.SelectSingleNode("//p").InnerText.Replace("&amp;", "&");
         string path  = doc.DocumentNode.SelectSingleNode("//a").GetAttributeValue("href", null);
         string thumb = doc.DocumentNode.SelectSingleNode("//img").GetAttributeValue("src", null);
         var    m     = new CurseMenuItem(title, path, thumb);
         return(m);
     }
     catch
     {
         return(null);
     }
 }
예제 #2
0
        /// <summary>
        /// 解析插件栏目
        /// </summary>
        /// <param name="html"></param>
        /// <returns></returns>
        public static List <CurseMenuItem> PraseCategory(string html)
        {
            var          mls = new List <CurseMenuItem>();
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            var          parent = doc.DocumentNode.SelectSingleNode("//ul[contains(@class,'categories-tier')]");
            HtmlDocument xdoc   = new HtmlDocument();

            xdoc.LoadHtml(parent.InnerHtml);
            mls.Add(new CurseMenuItem("ALL", "", "https://media.forgecdn.net/avatars/thumbnails/54/513/64/64/636135265289061589.png"));
            foreach (var n in xdoc.DocumentNode.SelectNodes("li"))
            {
                string ty = n.GetAttributeValue("data-root", "sub").ToLower();
                if (ty.Equals("false"))
                {
                    var cmi = CurseMenuItem.TryPrase(n.InnerHtml);
                    mls.Add(cmi);
                }
                else if (ty.Equals("true"))
                {
                    var cmi = CurseMenuItem.TryPrase(n.InnerHtml);
                    mls.Add(cmi);
                }
                else
                {
                    var cdoc = new HtmlDocument();
                    cdoc.LoadHtml(n.InnerHtml);
                    foreach (var cn in cdoc.DocumentNode.SelectNodes("//li"))
                    {
                        var cld = CurseMenuItem.TryPrase(cn.InnerHtml);
                        mls.Last().addChild(cld);
                    }
                }
            }
            return(mls);
        }
예제 #3
0
 public void addChild(CurseMenuItem c)
 {
     c.path = this.path + "/" + c.path;
     childs.Add(c);
 }