diff --git a/Classes/ChapterPaozwClass.cs b/Classes/ChapterPaozwClass.cs new file mode 100644 index 0000000000000000000000000000000000000000..b3510e8432eb1a780c9449c25ef507e352022b9c --- /dev/null +++ b/Classes/ChapterPaozwClass.cs @@ -0,0 +1,120 @@ +using HtmlAgilityPack; +using HtmlToTxtWFA.Utils; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace HtmlToTxtWFA.Classes +{ + /// + /// 章节 Nfxs + /// + public class ChapterPaozwClass : ChapterClass + { + public ChapterPaozwClass() { } + + public ChapterPaozwClass(HtmlNode aElement, bool isStarted) + { + // 第1章 洪战 + string label = aElement.InnerText; + if (!isStarted && (label.StartsWith("第1章") || label.StartsWith("第一章"))) + { + this.Label = label; + this.Url = aElement.GetAttributeValue("href", ""); + } + else if (isStarted && label.Contains("第") && label.Contains("章")) + { + this.Label = label; + this.Url = aElement.GetAttributeValue("href", ""); + } + } + + public override List ReadChapterList(string HOST, string serialNumber) + { + HtmlWeb web = new HtmlWeb(); + HtmlAgilityPack.HtmlDocument doc; + HtmlNodeCollection conNodes; + //从url中加载 + doc = web.LoadFromWebAsync(HOST + "/biquge/" + serialNumber + "/", Encoding.UTF8).Result; + if (doc == null) + { + MessageBox.Show("获取章节列表异常"); + return new List(); + } + + conNodes = doc.DocumentNode.SelectNodes("//*[@id=\"list\"]"); + if (conNodes == null || conNodes.Count == 0) + { + MessageBox.Show("获取章节列表异常"); + return new List(); + } + + HtmlNodeCollection aNodes = conNodes[0].SelectNodes(".//a"); + if (aNodes == null || aNodes.Count == 0) + { + MessageBox.Show("获取章节列表异常"); + return new List(); + } + + bool isStarted = false; + List chapterList = new List(); + for (int c = 0; c < aNodes.Count; c++) + { + // 第1章 洪战 + HtmlNode aNode = aNodes[c]; + if (aNode == null) + { + continue; + } + + ChapterPaozwClass chapterClass = new ChapterPaozwClass(aNode, isStarted); + if (!chapterClass.IsNull()) + { + chapterList.Add(chapterClass); + if (!isStarted) + { + isStarted = true; + } + } + } + + return chapterList; + } + + public override void ToTxt(string filePath, string HOST) + { + //从url中加载 + //第一页 + HtmlAgilityPack.HtmlDocument doc = new HtmlWeb().LoadFromWebAsync(HOST + this.Url, Encoding.UTF8).Result; + if (doc == null) + { + return; + } + + HtmlNodeCollection conNodes = doc.DocumentNode.SelectNodes("//article[@id=\"content\"]"); + if (conNodes == null || conNodes.Count == 0) + { + return; + } + + TxtUtil.Write(filePath, + " " + this.Label + "\n\n" + + conNodes[0].InnerHtml.Replace("

", " ").Replace("

", "\n\n")); + + //第二页 + doc = new HtmlWeb().LoadFromWebAsync(HOST + this.Url.Replace(".html", "_2.html"), Encoding.UTF8).Result; + if (doc == null) + { + return; + } + + conNodes = doc.DocumentNode.SelectNodes("//article[@id=\"content\"]"); + if (conNodes == null || conNodes.Count == 0) + { + return; + } + + TxtUtil.Write(filePath, conNodes[0].InnerHtml.Replace("

", " ").Replace("

", "\n\n")); + } + } +} diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index de24ad839649e16882dd41b646f4593251ca2589..2be8fc35c0225ec1c14691dc0a6ffa9f4b50f3a3 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -164,6 +164,7 @@ namespace HtmlToTxtWFA "键盘小说网", "乐文小说网", "农夫小说网", + "泡泡中文", "速读谷"}); this.platformComboBox.Location = new System.Drawing.Point(84, 7); this.platformComboBox.Name = "platformComboBox"; diff --git a/MainForm.cs b/MainForm.cs index 60468404412c1675dd715c0b875d1bc4bcf657b1..4cffbb727cb5d952d5ff76a894f216ea7aa91efb 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -19,6 +19,7 @@ namespace HtmlToTxtWFA ["键盘小说网"] = "http://www.janpn.info", ["乐文小说网"] = "https://www.xlewen.com/", ["农夫小说网"] = "https://www.nfxs.com", + ["泡泡中文"] = "https://www.paozw.com", ["速读谷"] = "https://www.sudugu.com", }; @@ -125,6 +126,10 @@ namespace HtmlToTxtWFA { chapterList = new ChapterNfxsClass().ReadChapterList(host, serialNumber); } + else if (platform.Equals("泡泡中文")) + { + chapterList = new ChapterPaozwClass().ReadChapterList(host, serialNumber); + } else if (platform.Equals("速读谷")) { chapterList = new ChapterSuduguClass().ReadChapterList(host, serialNumber);