From 10d4ddc4d49536f08e09c7414813f72b14be0776 Mon Sep 17 00:00:00 2001 From: Fengshaoyuan <1914442689@qq.com> Date: Wed, 15 May 2024 09:43:36 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=89=A9=E5=B1=95Xdu7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/ChapterPaozwClass.cs | 2 +- Classes/ChapterXdu7Class.cs | 106 +++++++++++++++++++++++++++++++++++ MainForm.Designer.cs | 1 + MainForm.cs | 5 ++ 4 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 Classes/ChapterXdu7Class.cs diff --git a/Classes/ChapterPaozwClass.cs b/Classes/ChapterPaozwClass.cs index b3510e8..1c96592 100644 --- a/Classes/ChapterPaozwClass.cs +++ b/Classes/ChapterPaozwClass.cs @@ -7,7 +7,7 @@ using System.Windows.Forms; namespace HtmlToTxtWFA.Classes { /// - /// 章节 Nfxs + /// 章节 Paozw /// public class ChapterPaozwClass : ChapterClass { diff --git a/Classes/ChapterXdu7Class.cs b/Classes/ChapterXdu7Class.cs new file mode 100644 index 0000000..815199a --- /dev/null +++ b/Classes/ChapterXdu7Class.cs @@ -0,0 +1,106 @@ +using HtmlAgilityPack; +using HtmlToTxtWFA.Utils; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace HtmlToTxtWFA.Classes +{ + /// + /// 章节 Xdu7 + /// + public class ChapterXdu7Class : ChapterClass + { + public ChapterXdu7Class() { } + + public ChapterXdu7Class(HtmlNode aElement, bool isStarted) + { + // 第1章 洪战 + string label = aElement.InnerText; + if (!isStarted && (label.StartsWith("第1章") || label.StartsWith("第一章") || label.StartsWith("第1回") || label.StartsWith("第一回"))) + { + this.Label = label; + this.Url = aElement.GetAttributeValue("href", ""); + } + else if (isStarted && label.Contains("第") && (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 + "/html/" + 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; + } + + ChapterXdu7Class chapterClass = new ChapterXdu7Class(aNode, isStarted); + if (!chapterClass.IsNull()) + { + chapterList.Add(chapterClass); + if (!isStarted) + { + isStarted = true; + } + } + } + + return chapterList; + } + + public override void ToTxt(string filePath, string HOST) + { + // 从url中加载 + // https://www.xdu7.la/html/227105/188410869.html + HtmlAgilityPack.HtmlDocument doc = new HtmlWeb().LoadFromWebAsync(HOST + this.Url, Encoding.UTF8).Result; + if (doc == null) + { + return; + } + + HtmlNodeCollection conNodes = doc.DocumentNode.SelectNodes("//div[@id='content']"); + if (conNodes == null || conNodes.Count == 0) + { + return; + } + + //移除底部导航菜单 + TxtUtil.Write(filePath, " " + this.Label + "\n\n" + + conNodes[0].InnerHtml.Split("
")[0].Replace("

", " ").Replace("

", "\n\n") + + "\n\n"); + } + } +} diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 2be8fc3..1f179f3 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -161,6 +161,7 @@ namespace HtmlToTxtWFA "4020电子书下载", "7小说", "笔趣阁", + "读趣网", "键盘小说网", "乐文小说网", "农夫小说网", diff --git a/MainForm.cs b/MainForm.cs index 4cffbb7..5e8d61c 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -16,6 +16,7 @@ namespace HtmlToTxtWFA ["4020电子书下载"] = "https://www.iwurexs.net", ["7小说"] = "https://www.7qs.org", ["笔趣阁"] = "http://www.ibiquge.cc", + ["读趣网"] = "https://www.xdu7.la", ["键盘小说网"] = "http://www.janpn.info", ["乐文小说网"] = "https://www.xlewen.com/", ["农夫小说网"] = "https://www.nfxs.com", @@ -114,6 +115,10 @@ namespace HtmlToTxtWFA { chapterList = new ChapterIbiqugeClass().ReadChapterList(host, serialNumber); } + else if (platform.Equals("读趣网")) + { + chapterList = new ChapterXdu7Class().ReadChapterList(host, serialNumber); + } else if (platform.Equals("键盘小说网")) { chapterList = new ChapterJianpanClass().ReadChapterList(host, serialNumber); -- Gitee