public static CurseMenuItem TryPrase(string html) { try { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml("<html>" + html + "</html>"); string title = doc.DocumentNode.SelectSingleNode("//p").InnerText.Replace("&", "&"); 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); } }
/// <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); }
public void addChild(CurseMenuItem c) { c.path = this.path + "/" + c.path; childs.Add(c); }