예제 #1
0
        /// <summary>
        /// 打开书籍信息页面
        /// </summary>
        /// <param name="r"></param>
        /// <param name="url"></param>
        public void OpenInfoPage(BookRule r, string url)
        {
            w("打开书籍页面:" + url);
            string html = Url.GetHtml(url, r.CharSet);
            var    info = (BookInfo)SetMatchResult(typeof(BookInfo), html, r.InfoRule).FirstOrDefault();

            ContentFilter f = new ContentFilter();

            info.intro = f.Filter(info.intro);

            CurBook = GetCurrentBook(info);

            //下载设置图片
            if (info.image.IsNullOrEmpty() == false)
            {
                GetImage(r, info.image.AppendToDomain(RootUrl));
                string nPath = string.Format("{0}{1}.jpg", System.AppDomain.CurrentDomain.BaseDirectory, "xxx");
                string upUrl = string.Format("{0}?a=savebookface&id={1}", ApiUrl, CurBook.ID);
                Url.UpLoadFile(nPath, upUrl, false);
            }

            //判断是够需要打开章节列表页面
            if (r.ChapterListUrlRule.IsNullOrEmpty() == false &&
                html.GetMatchGroup(r.ChapterListUrlRule).Groups.Count > 0
                )
            {
                string url_ChapterList  = html.GetMatch(r.ChapterListUrlRule).FirstOrDefault().AppendToDomain(RootUrl);
                string html_ChapterList = Url.GetHtml(url_ChapterList, r.CharSet);
                OpenChapterList(r, html_ChapterList);
            }
            else
            {
                OpenChapterList(r, html);
            }
        }
예제 #2
0
        public void Test001b_Filter_FilterDuplicates()
        {
            //Arrange
            var source = new ContentFilter();

            //Act
            var r = source.Filter(new List <string>()
            {
                "caca", "b", "caca"
            });

            //Assert
            Assert.AreEqual(new List <string>()
            {
                "caca", "b"
            }, r);
        }
예제 #3
0
        public void Test001a_Filter_AllDifferentKeepsTheSame()
        {
            //Arrange
            var source = new ContentFilter();

            //Act
            var r = source.Filter(new List <string>()
            {
                "a", "b"
            });

            //Assert
            Assert.AreEqual(new List <string>()
            {
                "a", "b"
            }, r);
        }
예제 #4
0
        /// <summary>
        /// 打开章节内容页面
        /// </summary>
        /// <param name="r"></param>
        /// <param name="url"></param>
        public void OpenChapterPage(BookRule r, string url)
        {
            int errorCount = 0;

begin:
            try
            {
                Console.WriteLine(string.Format("打开章节:{0}", url));
                string html   = Url.GetHtml(url, r.CharSet);
                var    result = (ChapterContent)SetMatchResult(typeof(ChapterContent), html, r.ContentRule).FirstOrDefault();

                string        chapterContent = GetChapterContent(r, html);
                ContentFilter f = new ContentFilter();
                chapterContent = f.Filter(chapterContent);

                chapterContent = chapterContent.HtmlDeCode();

                SaveChapter(result, chapterContent);

                //判断是否翻页
                if (r.NextChapterUrlRule.IsNullOrEmpty() == false &&
                    html.GetMatchGroup(r.NextChapterUrlRule).Groups.Count > 0
                    )
                {
                    //处理下一页
                    OpenChapterPage(r, html.GetMatch(r.NextChapterUrlRule).FirstOrDefault().AppendToDomain(RootUrl));
                }
            }
            catch
            {
                errorCount++;
                if (errorCount < 3)
                {
                    goto begin;
                }
                else
                {
                    throw new Exception("章节打开分析失败。");
                }
            }
        }