public static MangaCategoryVM GetMangaCategory(MangaCategorySourceType sourceType) { MangaCategoryVM ret = new MangaCategoryVM(); ret.Categories = new List <MangaCategoryItem>(); var model = MangaDatabaseHelper.GetMangaCategoryByType(sourceType); if (model != null && model.Count > 0) { foreach (var m in model) { MangaCategoryItem temp = new MangaCategoryItem(); temp.Category = m.Category; temp.IsRoot = m.Category == "全部"; temp.RootCategory = m.RootCategory; temp.Url = m.Url; ret.Categories.Add(temp); } } else { ret.MsgCode = VMCode.Error; ret.Msg = "没有找到Type = " + sourceType + " 的漫画分类"; } return(ret); }
public static void InitHanhanCategory(string htmlContent) { HtmlDocument document = new HtmlDocument(); document.LoadHtml(htmlContent); var categoryPath = "//div[@class='filter-item clearfix']"; var categoryNodes = document.DocumentNode.SelectNodes(categoryPath); if (categoryNodes != null && categoryNodes.Count > 0) { foreach (var node in categoryNodes) { var rootNode = node.ChildNodes.FindFirst("label"); if (rootNode != null) { MangaCategory temp = new MangaCategory(); temp.SourceType = MangaCategorySourceType.憨憨漫画; temp.RootCategory = rootNode.InnerHtml; var categoryNode = node.ChildNodes.FindFirst("ul").ChildNodes; foreach (var subNode in categoryNode) { var aTag = subNode.ChildNodes.FindFirst("a"); if (aTag != null) { var url = aTag.Attributes["href"].Value.Trim(); var name = aTag.InnerHtml.Trim(); if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(name)) { url = url.Substring(url.IndexOf("/list/") + "/list/".Length); temp.Url = string.IsNullOrEmpty(url) ? "" : url.Substring(0, url.LastIndexOf("/")); temp.Category = name; MangaDatabaseHelper.InsertMangaCategory(temp); } } } } } } }