From 70ec3f58b09a9021a0365a11b609cd4c9892f179 Mon Sep 17 00:00:00 2001 From: Fengshaoyuan <1914442689@qq.com> Date: Thu, 16 May 2024 09:50:52 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=89=A9=E5=B1=95Tycqzw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/ChapterTycqzwClass.cs | 105 ++++++++++++++++++++++++++++++++++ MainForm.Designer.cs | 3 +- MainForm.cs | 5 ++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 Classes/ChapterTycqzwClass.cs diff --git a/Classes/ChapterTycqzwClass.cs b/Classes/ChapterTycqzwClass.cs new file mode 100644 index 0000000..6ef3dd2 --- /dev/null +++ b/Classes/ChapterTycqzwClass.cs @@ -0,0 +1,105 @@ +using HtmlAgilityPack; +using HtmlToTxtWFA.Utils; +using System.Collections.Generic; +using System.Text; +using System.Windows.Forms; + +namespace HtmlToTxtWFA.Classes +{ + /// + /// 章节 Tycqzw + /// + public class ChapterTycqzwClass : ChapterClass + { + public ChapterTycqzwClass() { } + + public ChapterTycqzwClass(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中加载 + // http://www.tycqzw.net/135_135226/ + doc = web.LoadFromWebAsync(HOST + "/" + 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; + } + + ChapterTycqzwClass chapterClass = new ChapterTycqzwClass(aNode, isStarted); + if (!chapterClass.IsNull()) + { + chapterList.Add(chapterClass); + if (!isStarted) + { + isStarted = true; + } + } + } + + return chapterList; + } + + public override void ToTxt(string filePath, string HOST) + { + // 从url中加载 + // http://www.tycqzw.net/135_135226/48271449.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\n" + conNodes[0].InnerText.Replace(" ", " ").Split("(本章完)")[0].Split("推荐")[0]); + } + } +} diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 85edd09..278bbcc 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -168,7 +168,8 @@ namespace HtmlToTxtWFA "乐文小说网", "农夫小说网", "泡泡中文", - "速读谷"}); + "速读谷", + "天域小说网"}); this.platformComboBox.Location = new System.Drawing.Point(84, 7); this.platformComboBox.Name = "platformComboBox"; this.platformComboBox.Size = new System.Drawing.Size(107, 23); diff --git a/MainForm.cs b/MainForm.cs index 9930ada..815bdb0 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -24,6 +24,7 @@ namespace HtmlToTxtWFA ["农夫小说网"] = "https://www.nfxs.com", ["泡泡中文"] = "https://www.paozw.com", ["速读谷"] = "https://www.sudugu.com", + ["天域小说网"] = "http://www.tycqzw.net", }; private List chapterList = new List(); @@ -149,6 +150,10 @@ namespace HtmlToTxtWFA { chapterList = new ChapterSuduguClass().ReadChapterList(host, serialNumber); } + else if (platform.Equals("天域小说网")) + { + chapterList = new ChapterTycqzwClass().ReadChapterList(host, serialNumber); + } else { MessageBox.Show("查询章节信息异常:平台暂不支持"); -- Gitee