本帖最后由 TZ糖纸 于 2022-3-5 10:28 编辑
[C#] 纯文本查看 复制代码 public class Program
{
private static string baseUrl = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
private static void Main(string[] args)
{
string baseReUrl = "https://www.biduoxs.com/";
var client = new RestClient("https://www.biduoxs.com/biquge/17_17005/");
var request = new RestRequest();
Task<RestResponse> response = client.ExecuteAsync(request);
//Console.WriteLine(response.Result.Content);
var html = response.Result.Content;
HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(html);
var list = htmlDoc.DocumentNode.SelectNodes("//*[@id=\"list\"]/dl/dd/a");
foreach (var item in list)
{
Console.WriteLine(item.InnerText);
//Console.WriteLine(item.Attributes["href"].Value);
System.IO.File.AppendAllText(baseUrl + "xs.txt", item.InnerText + "\n\r");
client = new RestClient(baseReUrl + item.Attributes["href"].Value);
response = client.ExecuteAsync(request);
var html2 = response.Result.Content;
HtmlAgilityPack.HtmlDocument htmlDoc2 = new HtmlAgilityPack.HtmlDocument();
htmlDoc2.LoadHtml(html2);
var content = htmlDoc2.GetElementbyId("content").InnerHtml.Replace("<br>", "\n\r").Replace(" ", " ");
System.IO.File.AppendAllText(baseUrl + "xs.txt", content);
}
}
}
Nuget 包
RestSharp
HtmlAgilityPack
这里填写小说的目录链接
txt保存在程序的根目录自行查看 |