protected override void GetDirectoryListDelegate() { novel = null; novel = new Novel { NovelAddress = this.address }; WebClient webclient = new WebClient { Credentials = CredentialCache.DefaultCredentials //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据 }; Byte[] pageData; string pageHtml = null; for (int loop = 0; loop < this.repeatCount; loop++) { try { pageData = webclient.DownloadData(this.address); pageHtml = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句 break; } catch { } finally { webclient.Dispose(); } //获取失败 if (loop == 4) { this.TellGetCatalogFail(this); return; } } pageData = null; //获取小说名称 string[] str1 = pageHtml.Split(new string[] { "<h1>", "</h1>", "者:", "<dl>", "</dl>" }, StringSplitOptions.RemoveEmptyEntries); pageHtml = null; if (str1.Length < 5) { this.TellGetCatalogFail(this); return; } novel.NovelName = str1[1]; //获取作者姓名 string[] str2 = str1[3].Split(new string[] { "</p" }, StringSplitOptions.RemoveEmptyEntries); if (str2.Length > 1) { novel.Author = str2[0]; } //获取章节 string[] str3 = str1[4].Split(new string[] { "正文卷" }, StringSplitOptions.RemoveEmptyEntries); if (str3.Length < 2) { this.TellGetCatalogFail(this); return; } string[] str5 = str3[1].Split(new string[] { "<dd>" }, StringSplitOptions.RemoveEmptyEntries); string[] str4 = null; for (int i = 1; i < str5.Length; i++) { str4 = str5[i].Split(new string[] { "href=\"", "\">", "</a>" }, StringSplitOptions.RemoveEmptyEntries); if (str4.Length > 3) { if (!str4[1].StartsWith("javascript")) { novel.AddChapter(str4[2], "http://www.31xs.net" + str4[1]); } } str4 = null; } //创建以小说名为名称的文件夹 //this.savedFolder = this.savedFolder + novel.NovelName; if (this.savedFolder.EndsWith(@"\")) { this.novel.LocalFolder = this.savedFolder + novel.NovelName; } else { this.novel.LocalFolder = this.savedFolder + "\\" + novel.NovelName; } if (Directory.Exists(this.novel.LocalFolder)) { } else { Directory.CreateDirectory(this.novel.LocalFolder); } this.TellNovelDirectoryGetted(this, this.novel); }
protected override void GetDirectoryListDelegate() { novel = null; novel = new Novel(); novel.NovelAddress = this.address; WebClient webclient = new WebClient(); webclient.Credentials = CredentialCache.DefaultCredentials; //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据 Byte[] pageData; string pageHtml = null; for (int loop = 0; loop < this.repeatCount; loop++) { try { pageData = webclient.DownloadData(this.address); pageHtml = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句 break; } catch { } finally { webclient.Dispose(); } //获取失败 if (loop == 4) { this.TellGetCatalogFail(this); return; } } pageData = null; //获取小说名称 string[] str1 = pageHtml.Split(new string[] { "bname", "</h1>", "<h3>", "</h3>", "defaulthtml4" }, StringSplitOptions.RemoveEmptyEntries); pageHtml = null; if (str1.Length < 6) { this.TellGetCatalogFail(this); return; } if (str1[1].Length < 3) { this.TellGetCatalogFail(this); return; } novel.NovelName = str1[1].Substring(2, str1[1].Length - 2).Trim(); if (novel.NovelName.Length <= 0) { this.TellGetCatalogFail(this); return; } //作者 novel.Author = str1[3]; //抽取章节名称和章节地址 string[] str2 = str1[5].Split(new string[] { "<table", "</table>" }, StringSplitOptions.RemoveEmptyEntries); str1 = null; if (str2.Length < 3) { this.TellGetCatalogFail(this); return; } string chapterAll = str2[1]; str2 = null; //StringBuilder sbChapters = new StringBuilder(str1[2], str1[2].Length); //str1 = null; //sbChapters.Replace("\r\n\t\t", string.Empty); ////sbChapters.Replace("\x09\x09\x20\x20\x20\x20", string.Empty); ////byte[] tempb = Encoding.Default.GetBytes(sbChapters.ToString()); ////Regex.Replace(str1[2],"[\r\n\t\x09]", ////sbChapters.Replace(" ", string.Empty); //string chapterAll = sbChapters.ToString(); //sbChapters = null; string[] chapterList = chapterAll.Split(new string[] { "dccss\">" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < chapterList.Length; i++) { if (chapterList[i].StartsWith("<a href")) { //NovelChapter nc = new NovelChapter( string[] temp = chapterList[i].Split(new string[] { "href=\"", "\" alt=\"", "\">" }, StringSplitOptions.RemoveEmptyEntries); if (temp.Length < 3) { continue; } novel.AddChapter(temp[2], novel.NovelAddress + temp[1]); temp = null; } } //创建以小说名为名称的文件夹 //this.savedFolder = this.savedFolder + novel.NovelName; if (this.savedFolder.EndsWith(@"\")) { this.novel.LocalFolder = this.savedFolder + novel.NovelName; } else { this.novel.LocalFolder = this.savedFolder + "\\" + novel.NovelName; } if (Directory.Exists(this.novel.LocalFolder)) { } else { Directory.CreateDirectory(this.novel.LocalFolder); } this.TellNovelDirectoryGetted(this, this.novel); }
protected override void GetDirectoryListDelegate() { novel = null; novel = new Novel(); novel.NovelAddress = this.address; WebClient webclient = new WebClient(); webclient.Credentials = CredentialCache.DefaultCredentials; //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据 Byte[] pageData; string pageHtml = null; for (int loop = 0; loop < this.repeatCount; loop++) { try { pageData = webclient.DownloadData(this.address); pageHtml = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句 break; } catch { } finally { webclient.Dispose(); } //获取失败 if (loop == 4) { this.TellGetCatalogFail(this); return; } } pageData = null; //获取小说名称 string[] str1 = pageHtml.Split(new string[] { "class=\"infot\"><h1>", "</h1><span>作者:", "</span><a href=\"#bottom\">" }, StringSplitOptions.RemoveEmptyEntries); pageHtml = null; if (str1.Length < 4) { this.TellGetCatalogFail(this); return; } novel.NovelName = str1[1]; novel.Author = str1[2]; //int index = str1[1].IndexOf("</span"); //if (index < 2) { this.TellGetCatalogFail(this); return; } //novel.NovelName = str1[1].Substring(2, index - 2).Trim(); //if (novel.NovelName.Length <= 0) { this.TellGetCatalogFail(this); return; } //index = str1[1].IndexOf("aspx"); //int index1 = str1[1].IndexOf("</a>"); //if (index < 0 || index1 < 0 || index1 < index + 6) { this.TellGetCatalogFail(this); return; } //novel.Author = str1[1].Substring(index + 6, index1 - index - 6); StringBuilder sbChapters = new StringBuilder(str1[3], str1[3].Length); str1 = null; sbChapters.Replace("\r\n\t\t", string.Empty); //sbChapters.Replace("\x09\x09\x20\x20\x20\x20", string.Empty); //byte[] tempb = Encoding.Default.GetBytes(sbChapters.ToString()); //Regex.Replace(str1[2],"[\r\n\t\x09]", //sbChapters.Replace(" ", string.Empty); string chapterAll = sbChapters.ToString(); sbChapters = null; string[] chapterList = chapterAll.Split(new string[] { "<DIV class=dccss>" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 1; i < chapterList.Length; i++) { string[] temp = chapterList[i].Split(new string[] { "<a href=\"", "\" target=\"_blank\">", "</a>" }, StringSplitOptions.RemoveEmptyEntries); if (temp.Length < 3) { continue; } novel.AddChapter(temp[2], "http://www.kenshuge.com" + temp[1]); //if (chapterList[i].StartsWith("<a href")) //{ // //NovelChapter nc = new NovelChapter( // string[] temp = chapterList[i].Split(new string[] { "\"", ">", "</a" }, StringSplitOptions.RemoveEmptyEntries); // novel.AddChapter(temp[4], "http://www.kenshuge.com" + temp[1]); // temp = null; //} } //创建以小说名为名称的文件夹 //this.savedFolder = this.savedFolder + novel.NovelName; if (this.savedFolder.EndsWith(@"\")) { this.novel.LocalFolder = this.savedFolder + novel.NovelName; } else { this.novel.LocalFolder = this.savedFolder + "\\" + novel.NovelName; } if (Directory.Exists(this.novel.LocalFolder)) { } else { Directory.CreateDirectory(this.novel.LocalFolder); } this.TellNovelDirectoryGetted(this, this.novel); }
protected override void GetDirectoryListDelegate() { novel = null; novel = new Novel(); novel.NovelAddress = this.address; WebClient webclient = new WebClient(); webclient.Credentials = CredentialCache.DefaultCredentials; //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据 Byte[] pageData; string pageHtml = null; for (int loop = 0; loop < this.repeatCount; loop++) { try { pageData = webclient.DownloadData(this.address); pageHtml = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句 break; } catch { } finally { webclient.Dispose(); } //获取失败 if (loop == 4) { this.TellGetCatalogFail(this); return; } } pageData = null; //获取小说名称 string[] str1 = pageHtml.Split(new string[] { "<h1>", "</h1>", "作 者:" }, StringSplitOptions.RemoveEmptyEntries); pageHtml = null; if (str1.Length < 4) { this.TellGetCatalogFail(this); return; } novel.NovelName = str1[1]; //获取作者姓名 int tempIndex = str1[3].IndexOf("</p>", 0); novel.Author = str1[3].Substring(0, tempIndex); string[] str2 = str1[3].Split(new string[] { "<dl>", "</dl>" }, StringSplitOptions.RemoveEmptyEntries); str1 = null; if (str2.Length < 3) { this.TellGetCatalogFail(this); return; } string[] str3 = str2[1].Split(new string[] { "<dd>", "</dd>" }, StringSplitOptions.RemoveEmptyEntries); str2 = null; if (str3.Length < 1) { this.TellGetCatalogFail(this); return; } for (int i = 0; i < str3.Length; i++) { if (str3[i].StartsWith("<a href=") && str3[i].EndsWith("</a>")) { string[] str4 = str3[i].Split(new string[] { "href=", "title=", ">" }, StringSplitOptions.RemoveEmptyEntries); novel.AddChapter(str4[2].Substring(1, str4[2].Length - 2), "http://www.biquge.com" + str4[1].Substring(1, str4[1].Length - 3)); str4 = null; } } //创建以小说名为名称的文件夹 //this.savedFolder = this.savedFolder + novel.NovelName; if (this.savedFolder.EndsWith(@"\")) { this.novel.LocalFolder = this.savedFolder + novel.NovelName; } else { this.novel.LocalFolder = this.savedFolder + "\\" + novel.NovelName; } if (Directory.Exists(this.novel.LocalFolder)) { } else { Directory.CreateDirectory(this.novel.LocalFolder); } this.TellNovelDirectoryGetted(this, this.novel); }
protected override void GetDirectoryListDelegate() { novel = null; novel = new Novel(); novel.NovelAddress = this.address; WebClient webclient = new WebClient(); webclient.Credentials = CredentialCache.DefaultCredentials; //获取或设置用于对向Internet资源的请求进行身份验证的网络凭据 Byte[] pageData; string pageHtml = null; for (int loop = 0; loop < this.repeatCount; loop++) { try { pageData = webclient.DownloadData(this.address); pageHtml = Encoding.Default.GetString(pageData); //如果获取网站页面采用的是GB2312,则使用这句 break; } catch { } finally { webclient.Dispose(); } //获取失败 if (loop == 4) { this.TellGetCatalogFail(this); return; } } pageData = null; //获取小说名称 string[] str1 = pageHtml.Split(new string[] { "</a> -><a href=", "</a></dt><dd><h1>", "<h3>作者:", "</h3></dd><dd>" }, StringSplitOptions.RemoveEmptyEntries); pageHtml = null; if (str1.Length < 5) { this.TellGetCatalogFail(this); return; } string[] str2 = str1[1].Split(new string[] { ">" }, StringSplitOptions.RemoveEmptyEntries); if (str2.Length > 1) { novel.NovelName = str2[1]; } //获取作者姓名 novel.Author = str1[3]; string[] str3 = str1[4].Split(new string[] { "<td class=\"L\"><a href=\"" }, StringSplitOptions.RemoveEmptyEntries); string[] str4 = null; for (int i = 0; i < str3.Length; i++) { str4 = str3[i].Split(new string[] { "\">", "</a>" }, StringSplitOptions.RemoveEmptyEntries); if (str4.Length > 2) { if (novel.NovelAddress.EndsWith("/")) { novel.AddChapter(str4[1], novel.NovelAddress + str4[0]); } else { novel.AddChapter(str4[1], novel.NovelAddress + "/" + str4[0]); } } str4 = null; } //创建以小说名为名称的文件夹 //this.savedFolder = this.savedFolder + novel.NovelName; if (this.savedFolder.EndsWith(@"\")) { this.novel.LocalFolder = this.savedFolder + novel.NovelName; } else { this.novel.LocalFolder = this.savedFolder + "\\" + novel.NovelName; } if (Directory.Exists(this.novel.LocalFolder)) { } else { Directory.CreateDirectory(this.novel.LocalFolder); } this.TellNovelDirectoryGetted(this, this.novel); }