public async Task <ChapterLoadData> GetChapterNumber(Truyen truyen, int indexOfchapter) { var siteUrl = string.Format("{0}chuong-{1}/", truyen.TruyenUrl, indexOfchapter); var htmlData = await WebUtils.DoRequestSimpleGet(siteUrl); if (htmlData.Status) { var dom = new HtmlDocument(); dom.LoadHtml(htmlData.Data); var chapter = new Chapter(); chapter.IndexNumberPageOfChapter = indexOfchapter; chapter.PageOfChapter = indexOfchapter; var cdom = dom.DocumentNode.SelectSingleNode(TRUYEN_CONTENT_XPATH); if (cdom != null) { List <HtmlNode> listRemove = cdom.ChildNodes.Where(iNode => iNode.Name == "font").ToList(); foreach (var iNode in listRemove) { cdom.RemoveChild(iNode); } chapter.NoiDung = FixHtmlString(cdom.InnerHtml.ToString()); } else { return(null); } cdom = dom.DocumentNode.SelectSingleNode(TRUYEN_CONTENT_TIEUDE_XPATH); if (cdom != null) { var tmpString = cdom.InnerText.Trim(); chapter.TenChuong = tmpString.Substring(tmpString.IndexOf(':') + 1, tmpString.Length - tmpString.IndexOf(':') - 1).Trim(); } chapter.SoThuTu = "Chương " + indexOfchapter; chapter.IndexChapter = indexOfchapter; var lchapter = new List <Chapter>(); lchapter.Add(chapter); var result = new ChapterLoadData(); result.ListChapter = lchapter; result.MaxPageIndex = truyen.MaxPageTruyen; result.IndexStartOfChapter = indexOfchapter; return(result); } return(null); }
public async Task <ChapterLoadData> GetPageChapTer(Truyen truyen, int page, bool allowGetNoidung = true) { if (allowGetNoidung) { return(await GetChapterNumber(truyen, page)); } var htmlData = await WebUtils.DoRequestSimpleGet(truyen.TruyenUrl); if (htmlData.Status) { var dom = new HtmlDocument(); dom.LoadHtml(htmlData.Data); // the loai? var cDom = dom.DocumentNode.SelectSingleNode(CATEGORY_XPATH); if (cDom != null) { truyen.Category = cDom.InnerText.Trim(); } // mo ta? cDom = dom.DocumentNode.SelectSingleNode(MOTA_XPATH); if (cDom != null) { truyen.Description = FixHtmlString(WebUtility.HtmlDecode(cDom.InnerHtml.Trim())); } var lchapter = new List <Chapter>(); var maxPage = 0; var lDom = dom.DocumentNode.SelectNodes(CHUONGMOINHAT_XPATH); if (lDom != null) { foreach (var iDom in lDom) { var chap = new Chapter(); chap.TruyenUrl = truyen.TruyenUrl; cDom = iDom.SelectSingleNode("./a"); if (cDom != null) { var tmpString = cDom.InnerText.Trim(); chap.TenChuong = tmpString.Substring(tmpString.IndexOf(':') + 1, tmpString.Length - tmpString.IndexOf(':') - 1).Trim(); } else { continue; } var href = cDom.GetAttributeValue("href", ""); try { if (href.LastIndexOf("-") != -1) { href = href.Substring(href.LastIndexOf("-") + 1, href.Length - href.LastIndexOf('-') - 2); var num = int.Parse(href); chap.SoThuTu = "Chương " + num.ToString(); chap.IndexNumberPageOfChapter = num; chap.PageOfChapter = num; if (num > maxPage) { maxPage = num; } } else { continue; } } catch (Exception) { continue; } lchapter.Add(chap); } } // list chuong tu ddau lDom = dom.DocumentNode.SelectNodes(CHUONG_XPATH); if (lDom != null) { var i = 1; foreach (var iDom in lDom) { i++; var chap = new Chapter(); chap.TruyenUrl = truyen.TruyenUrl; cDom = iDom.SelectSingleNode(TENCHUONG_XPATH); if (cDom != null) { var tmpString = cDom.InnerText.Trim(); chap.TenChuong = tmpString.Substring(tmpString.IndexOf(':') + 1, tmpString.Length - tmpString.IndexOf(':') - 1).Trim(); } var href = cDom.GetAttributeValue("href", ""); try { if (href.LastIndexOf("-") != -1) { href = href.Substring(href.LastIndexOf("-") + 1, href.Length - href.LastIndexOf('-') - 2); var num = int.Parse(href); chap.SoThuTu = "Chương " + num; chap.IndexNumberPageOfChapter = num; chap.PageOfChapter = num; if (num > maxPage) { maxPage = num; } } else { continue; } } catch (Exception) { continue; } lchapter.Add(chap); } } truyen.MaxPageTruyen = maxPage; var result = new ChapterLoadData(); result.ListChapter = lchapter; result.MaxPageIndex = maxPage; NumberChapterPerPage = maxPage + 100; result.IndexStartOfChapter = 0; return(result); } return(null); }
public async Task <ChapterLoadData> GetPageChapTer(Truyen truyen, int page, bool allowGetNoidung = true) { var pageUrl = string.Format(TRUYEN_URL, truyen.TruyenUrl, page); var htmlData = await WebUtils.DoRequestSimpleGet(pageUrl, null, "", HOME_PAGE); if (htmlData.Status) { var dom = new HtmlDocument(); dom.LoadHtml(htmlData.Data); var chapterDoms = dom.DocumentNode.SelectNodes(DANH_SACH_CHUONG_XPATH); var maxPage = 1; if (chapterDoms != null) { var i = 0; var j = 0; var lchapter = new List <Chapter>(); foreach (var chapDom in chapterDoms) { i++; if (i < 3) { continue; } var chap = new Chapter(); HtmlNode tdom = null; chap.TruyenUrl = truyen.TruyenUrl; chap.PageOfChapter = page; tdom = chapDom.SelectSingleNode(CHUONGNUMBER_XPATH); if (tdom != null) { chap.SoThuTu = tdom.InnerText.Trim(); } tdom = chapDom.SelectSingleNode(TENCHUONG_XPATH); if (tdom != null) { chap.TenChuong = tdom.InnerText.Trim(); } else { continue; } tdom = chapDom.SelectSingleNode(SOURCE_XPATH); if (tdom != null) { chap.Nguon = tdom.InnerText.Trim(); } if (allowGetNoidung) { tdom = chapDom.SelectSingleNode(NOIDUNG_XPATH); if (tdom != null) { List <HtmlNode> listRemove = tdom.ChildNodes.Where(iNode => iNode.Name == "span").ToList(); foreach (var iNode in listRemove) { tdom.RemoveChild(iNode); } chap.NoiDung = tdom.InnerText.Trim(); } else { continue; } } chap.IndexNumberPageOfChapter = j++; lchapter.Add(chap); } var ldom = dom.DocumentNode.SelectNodes(MAX_PAGE_TRUYEN_XPATH); if (ldom != null) { foreach (var idom in ldom) { var cdom = idom.SelectSingleNode("./a"); if (cdom != null) { var href = cdom.GetAttributeValue("href", ""); if (href.IndexOf("=") != -1 && href.IndexOf("&") != -1) { try { href = href.Substring(href.IndexOf("=") + 1, href.IndexOf("&") - href.IndexOf("=") - 1); } catch (Exception) { // ignored } } var n = 0; int.TryParse(href, out n); if (n > maxPage) { maxPage = n; } } } } var result = new ChapterLoadData(); result.ListChapter = lchapter; result.MaxPageIndex = maxPage; result.IndexStartOfChapter = 0; return(result); } } return(null); }