From 4ef0befd17956c0205d62d70998de39f1df468e4 Mon Sep 17 00:00:00 2001 From: Fengshaoyuan <1914442689@qq.com> Date: Thu, 16 May 2024 15:38:44 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=89=A9=E5=B1=95qiubiquge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/ChapterQiubiqugeClass.cs | 118 +++++++++++++++++++++++++++++++ MainForm.Designer.cs | 3 +- MainForm.cs | 9 ++- 3 files changed, 127 insertions(+), 3 deletions(-) create mode 100644 Classes/ChapterQiubiqugeClass.cs diff --git a/Classes/ChapterQiubiqugeClass.cs b/Classes/ChapterQiubiqugeClass.cs new file mode 100644 index 0000000..dcd91df --- /dev/null +++ b/Classes/ChapterQiubiqugeClass.cs @@ -0,0 +1,118 @@ +using HtmlAgilityPack; +using HtmlToTxtWFA.Utils; +using System.Collections.Generic; +using System.IO; +using System.Net.Http; +using System.Text; +using System.Windows.Forms; + +namespace HtmlToTxtWFA.Classes +{ + /// + /// 章节 Qiubiquge + /// + public class ChapterQiubiqugeClass : ChapterClass + { + public ChapterQiubiqugeClass() { } + + public ChapterQiubiqugeClass(HtmlNode aElement) + { + // 第1章 善恶到头终有豹 + this.Label = aElement.InnerText; + this.Url = aElement.GetAttributeValue("href", ""); + } + + public override List ReadChapterList(string HOST, string serialNumber) + { + HtmlWeb web = new HtmlWeb(); + HtmlAgilityPack.HtmlDocument doc; + HtmlNodeCollection conNodes; + + // 从url中加载 + // https://www.qiubiquge.com/ml/97953/ + doc = web.LoadFromWebAsync(HOST + "/ml/" + serialNumber, Encoding.Default).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; + } + + ChapterQiubiqugeClass chapterClass = new ChapterQiubiqugeClass(aNode); + if (!chapterClass.IsNull()) + { + chapterList.Add(chapterClass); + if (!isStarted) + { + isStarted = true; + } + } + } + + return chapterList; + } + + public override void ToTxt(string filePath, string HOST) + { + // 第一页 + // 从url中加载 + // https://www.qiubiquge.com/ml/97953/2885453.html + HtmlAgilityPack.HtmlDocument doc = new HtmlWeb().LoadFromWebAsync(HOST + this.Url, Encoding.Default).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" + + conNodes[0].InnerHtml.Replace(" ", "").Replace("

", " ").Replace("

", "\n") + ); + + // 第二页 + // https://www.qiubiquge.com/ml/97953/2885453_2.html + doc = new HtmlWeb().LoadFromWebAsync(HOST + this.Url.Replace(".html", "_2.html"), Encoding.Default).Result; + if (doc == null) + { + return; + } + + conNodes = doc.DocumentNode.SelectNodes("//div[@id='content']"); + if (conNodes == null || conNodes.Count == 0) + { + return; + } + + TxtUtil.Write(filePath, conNodes[0].InnerHtml.Replace(" ", "").Replace("

", " ").Replace("

", "\n") + + "\n"); + } + } +} diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 278bbcc..5e3dc23 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -162,7 +162,8 @@ namespace HtmlToTxtWFA "3Q中文网", "4020电子书下载", "7小说", - "笔趣阁", + "i笔趣阁", + "qiu笔趣阁", "读趣网", "键盘小说网", "乐文小说网", diff --git a/MainForm.cs b/MainForm.cs index 815bdb0..1892f02 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -17,7 +17,8 @@ namespace HtmlToTxtWFA ["3Q中文网"] = "https://sk.3qxsw.org", ["4020电子书下载"] = "https://www.iwurexs.net", ["7小说"] = "https://www.7qs.org", - ["笔趣阁"] = "http://www.ibiquge.cc", + ["i笔趣阁"] = "http://www.ibiquge.cc", + ["qiu笔趣阁"] = "https://www.qiubiquge.com", ["读趣网"] = "https://www.xdu7.la", ["键盘小说网"] = "http://www.janpn.info", ["乐文小说网"] = "https://www.xlewen.com/", @@ -122,10 +123,14 @@ namespace HtmlToTxtWFA { chapterList = new Chapter7qsClass().ReadChapterList(host, serialNumber); } - else if (platform.Equals("笔趣阁")) + else if (platform.Equals("i笔趣阁")) { chapterList = new ChapterIbiqugeClass().ReadChapterList(host, serialNumber); } + else if (platform.Equals("qiu笔趣阁")) + { + chapterList = new ChapterQiubiqugeClass().ReadChapterList(host, serialNumber); + } else if (platform.Equals("读趣网")) { chapterList = new ChapterXdu7Class().ReadChapterList(host, serialNumber); -- Gitee