public string GetChapterContent(NVChapter nVChapter) { string html = HttpHelper.GetString(nVChapter.Link, baseEncoding); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); HtmlNode node = doc.GetElementbyId("oneboolt"); HtmlNode htmlNode = node.SelectSingleNode("//*[@class=\"noveltext\"]"); StringBuilder cSb = new StringBuilder(""); cSb.AppendLine(); cSb.Append(nVChapter.Title).AppendLine(); foreach (HtmlNode hn in htmlNode.ChildNodes) { if (hn.Name == "#text") { string s = hn.OuterHtml.Trim(); if (s.Length > 0) { cSb.Append(s).AppendLine(); } } } return(cSb.ToString()); }
public string GetChapterContent(NVChapter nVChapter) { var html = HttpHelper.GetString(nVChapter.Link, baseEncoding); Article article = Html2Article.GetArticle(html); var cSb = new StringBuilder(); cSb.AppendLine(); cSb.Append(nVChapter.Title).AppendLine(); cSb.Append(article.Content).AppendLine(); return(cSb.ToString()); }
public List <NVChapter> GetList(string url) { List <NVChapter> list = new List <NVChapter>(); string html = HttpHelper.GetString(url, baseEncoding); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); var nameNode = doc.DocumentNode.SelectSingleNode("//h1"); if (nameNode == null) { return(list); } string NovelName = nameNode.InnerHtml.Trim(); fileName = string.IsNullOrEmpty(NovelName) ? fileName : NovelName; // 获取文件名称 var chapterListNode = doc.DocumentNode.SelectSingleNode("//ul[starts-with(@class,'list-group list-charts')]"); if (chapterListNode == null) { return(list); } // Dim regStr1 As String = "<a([^>]*?)href=['""]([^'""]*?)['""]([^>]*?)>(.*?)<\/a>" string regStr1 = @"<a([^>]*?)href=['""]((/(\d*))*\.html)['""]([^>]*?)>(.*?)</a>"; MatchCollection matchs = Regex.Matches(chapterListNode.InnerHtml, regStr1); int index = 1; foreach (Match match in matchs) { if (match.Success) { var link = match.Groups[2].Value; var title = match.Groups[6].Value; var obj = new NVChapter(); obj.Title = title; obj.Link = String.Format("http://www.lwxslwxs.com{0}", link); obj.Sort = index; index += 1; list.Add(obj); } } return(list); }
public List <NVChapter> GetList(string url) { List <NVChapter> list = new List <NVChapter>(); string html = HttpHelper.GetString(url, baseEncoding); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); HtmlNode node = doc.GetElementbyId("oneboolt"); if (node == null) { return(list); } HtmlNode fn = node.SelectSingleNode("//*[@itemprop=\"articleSection\"]"); if (fn == null) { return(list); } string NovelName = fn.InnerHtml.Trim(); fileName = string.IsNullOrEmpty(NovelName) ? fileName : NovelName; // 获取文件名称 // Dim regStr1 As String = "<a([^>]*?)href=['""]([^'""]*?)['""]([^>]*?)>(.*?)<\/a>" string regStr1 = @"<a[^>]+href=\s*(?:'(?<href>[^']+)'|""(?<href>[^""]+)""|(?<href>[^>\s]+))\s*[^>]*>(?<text>.*?)</a>"; string regStr2 = @"http:\/\/www.jjwxc.net\/onebook.php\?novelid=\d*&chapterid=\d*"; MatchCollection matchs = Regex.Matches(html, regStr1); int index = 1; foreach (Match match in matchs) { Match rzt = Regex.Match(match.Value, regStr2); if (rzt.Success) { var obj = new NVChapter(); obj.Title = match.Groups["text"].Value; obj.Link = match.Groups["href"].Value; obj.Sort = index; index += 1; list.Add(obj); } } return(list); }