/// <summary> /// 从起点下载普通章节 /// </summary> /// <param name="ChapterUrl"></param> /// <returns></returns> protected string GetQidianNormalChapter(string ChapterUrl) { if (ChapterUrl.Contains("vip")) { return(null); } QidianRule Rule = Book.RulesOperate.GetQidianRule(); string HtmlQidianChapter = Url.Post(new NameValueCollection(), ChapterUrl, Encoding.GetEncoding(Rule.CharSet), new System.Net.CookieContainer(), "*.*", "http://www.qidian.com/", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.2 Safari/535.11" ); string txtUrl = HtmlQidianChapter.GetMatchGroup("<script src='(?<url>.*?)' charset='GB2312'></script>").Groups["url"].Value; if (txtUrl.IsNullOrEmpty()) { return(null); } string txt_Content = Url.GetHtml(txtUrl, "GB2312"); txt_Content = txt_Content.Replace("document.write('", ""); txt_Content = txt_Content.Replace("');", ""); //删除脚本 txt_Content = Regex.Replace(txt_Content, "<script [\\s\\S]*?</script>", "", RegexOptions.IgnoreCase); //删除链接 txt_Content = Regex.Replace(txt_Content, "<a [\\s\\S]*?</a>", "", RegexOptions.IgnoreCase); if (txt_Content.Contains("<img")) { return(""); } return(txt_Content); }
/// <summary> /// 为书籍设置封面 /// </summary> /// <param name="book"></param> public void UploadBookFace(Voodoo.Model.Book book) { string faceUrl = ""; string Title = book.Title.toUtf8String(); QidianRule Rule = Book.RulesOperate.GetQidianRule(); string QidianSearchUrl = string.Format(Rule.SearchPageUrl, Title); string QidianRefer = string.Format(Rule.SearchRefer, Title); //CollectStatus.Status = "正在搜索"; Status_Chage(); string SearchList = Voodoo.Net.Url.Post(new System.Collections.Specialized.NameValueCollection(), QidianSearchUrl, Encoding.GetEncoding(Rule.CharSet), new System.Net.CookieContainer(), "*.*", QidianRefer, "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.2 Safari/535.11"); //解析json数据 try { JavaScriptSerializer serializer = new JavaScriptSerializer(); var json = serializer.DeserializeObject(SearchList); var j = ((System.Collections.Generic.Dictionary <string, object>)((object[])(((object[])(json))[0]))[0]); faceUrl = string.Format("http://image.cmfu.com/books/{0}/{0}.jpg", j["BookId"].ToS()); //BH = new Voodoo.Basement.Client.BookHelper("http://localhost/"); Voodoo.Net.Url.DownFile(faceUrl, System.Environment.CurrentDirectory + "\\face.jpg"); BH.SetBookFace(book.ID, System.Environment.CurrentDirectory + "\\face.jpg"); } catch { //this.CollectStatus.Status = "起点没有这本书"; //this.Status_Chage(); } }
/// <summary> /// 保存起点规则 /// </summary> /// <param name="Rule"></param> public static void SaveQidianRule(QidianRule Rule) { XML.SaveSerialize(Rule, CFG + "\\QidianRule.xml"); }
/// <summary> /// 获取起点书籍 /// </summary> /// <param name="BookTitle"></param> /// <returns></returns> protected BookAndChapter GetQidianBook(string BookTitle) { BookAndChapter b = new BookAndChapter(); //搜索起点,获得json数据 string Title = BookTitle.toUtf8String(); QidianRule Rule = Book.RulesOperate.GetQidianRule(); string QidianSearchUrl = string.Format(Rule.SearchPageUrl, Title); string QidianRefer = string.Format(Rule.SearchRefer, Title); CollectStatus.Status = "正在搜索"; Status_Chage(); string SearchList = Voodoo.Net.Url.Post(new System.Collections.Specialized.NameValueCollection(), QidianSearchUrl, Encoding.GetEncoding(Rule.CharSet), new System.Net.CookieContainer(), "*.*", QidianRefer, "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.2 Safari/535.11"); //解析json数据 try { JavaScriptSerializer serializer = new JavaScriptSerializer(); var json = serializer.DeserializeObject(SearchList); var j = ((System.Collections.Generic.Dictionary <string, object>)((object[])(((object[])(json))[0]))[0]); b.ID = j["BookId"].ToS().ToInt32(); b.Author = j["AuthorName"].ToS(); b.Class = j["SubCategoryName"].ToS(); b.Intro = j["Description"].ToS(); b.BookTitle = j["BookName"].ToS().TrimHTML(); } catch { this.CollectStatus.Status = "起点没有这本书"; this.Status_Chage(); return(new BookAndChapter() { ID = 0, Chapters = new List <Chapter>() }); } //打开章节列表 CollectStatus.Status = "打开章节列表"; Status_Chage(); string url_ChapterList = string.Format(Rule.ChapterListUrl, b.ID.ToString()); string html_ChapterList = Url.Post(new System.Collections.Specialized.NameValueCollection(), url_ChapterList, Encoding.GetEncoding(Rule.CharSet), new System.Net.CookieContainer(), "*.*", "http://www.qidian.com/Book/" + b.ID + ".aspx", "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.2 Safari/535.11"); //查找章节 b.Chapters = new List <Chapter>(); var match_Chapter = html_ChapterList.GetMatchGroup(Rule.ChapterTitle); int i = 0; while (match_Chapter.Success) { b.Chapters.Add(new Chapter() { Title = match_Chapter.Groups["title"].Value, Url = match_Chapter.Groups["url"].Value.AppendToDomain("http://www.qidian.com/"), IsVip = match_Chapter.Groups["url"].Value.ToLower().Contains("vip"), Index = i }); i++; match_Chapter = match_Chapter.NextMatch(); } return(b); }