public static MangaDetailVM GetMangaDetail(MangaCategorySourceType sourceType, string path) { MangaDetailVM ret = new MangaDetailVM(); switch (sourceType) { case MangaCategorySourceType.憨憨漫画: ret = GetMangaDetailHanhan(sourceType, path); break; } return(ret); }
public static MangaDetailVM GetMangaDetailHanhan(MangaCategorySourceType sourceType, string path) { MangaDetailVM ret = new MangaDetailVM(); ret.Chapters = new List <MangaChapter>(); var htmlRet = HtmlManager.GetHtmlWebClient("http://www.hanhan.net", path); if (htmlRet.Success) { try { HtmlDocument document = new HtmlDocument(); document.LoadHtml(htmlRet.Content); var picPath = "//img[@class='pic']"; var detailPath = "//ul[@class='detail-list cf']/li"; var infoPath = "//div[@id='intro-all']//p"; var chapterPath = "//ul[@id='chapter-list-4']//a"; var picNode = document.DocumentNode.SelectSingleNode(picPath); var infoNode = document.DocumentNode.SelectSingleNode(infoPath); var chapterNodes = document.DocumentNode.SelectNodes(chapterPath); var detailNodes = document.DocumentNode.SelectNodes(detailPath); if (picNode != null) { ret.PicUrl = picNode.Attributes["src"].Value.Trim(); ret.MangaName = picNode.Attributes["alt"].Value.Trim(); } if (detailNodes != null && detailNodes.Count > 0) { foreach (var node in detailNodes) { if (node.Attributes.Count <= 0) { foreach (var subNode in node.ChildNodes) { if (subNode.InnerText.StartsWith("漫画作者:")) { ret.Author = subNode.InnerText.Replace("漫画作者:", ""); } } } else { ret.MangaStatus = node.ChildNodes.FindFirst("a").InnerHtml; ret.UpdateDate = DateTime.Parse(node.ChildNodes[1].ChildNodes[5].InnerText); ret.UpdateInfo = "更新到:" + node.ChildNodes[1].ChildNodes[7].InnerText; } } } if (infoNode != null) { ret.Description = infoNode.InnerText.Trim(); } if (chapterNodes != null) { foreach (var node in chapterNodes) { ret.Chapters.Add(new MangaChapter { Url = "http://www.hanhande.net" + node.Attributes["href"].Value.Trim(), ChapterName = node.ChildNodes.FindFirst("span").InnerText.Trim() }); } } } catch (Exception e) { ret.MsgCode = VMCode.Exception; ret.Msg = e.ToString(); } } else { ret.MsgCode = VMCode.Success; ret.Msg = "网页获取失败"; } return(ret); }