Exemple #1
0
        /// <summary>
        /// 按页解析
        /// </summary>
        /// <param name="pageNum"></param>
        protected override void ParsePageData(int pageNum)
        {
            m_url = m_url.TrimEnd('/') + "/article/list/" + pageNum;
            var Node = HttpUtils.GetHtmlNodeFromUrl(m_url);

            if (pageNum == 1)
            {
                string html = Node.InnerHtml;
                m_totalPostCount = JsUtil.GetJsNumVariable(html, @"var\s+listTotal\s*?=\s*?\d{1,3}");
                if (m_totalPostCount == 0)
                {
                    WinformUtil.ShowDialog("提示", "空空如也");
                    return;
                }
                m_perPagePostCount = JsUtil.GetJsNumVariable(html, @"var\s+pageSize\s*?=\s*?\d{1,3}");
                m_pageCount        = m_totalPostCount / m_perPagePostCount + (m_totalPostCount % m_perPagePostCount > 0 ? 1 : 0);
            }

            var postNodes = Node.SelectNodes(PerPageArticalList);

            if (postNodes != null)
            {
                int index = 0;
                m_articleList.Clear();
                foreach (var item in postNodes)
                {
                    var doc = new HtmlDocument();
                    doc.LoadHtml(item.InnerHtml);

                    var titleNode = doc.DocumentNode.SelectSingleNode(Title);
                    var timeNode  = doc.DocumentNode.SelectSingleNode(WriteTime);

                    Article       article = new Article();
                    StringBuilder builder = new StringBuilder(titleNode.InnerText);
                    builder.Replace("\n", "");
                    builder.Replace(" ", "");
                    article.Title = builder.ToString();
                    article.Time  = timeNode.InnerText;
                    article.Link  = titleNode.Attributes["href"].Value;
                    article.Id    = GetIdByUrl(article.Link);
                    article.Index = index;
                    m_articleList.Add(article);
                    ++index;
                }
            }
        }
Exemple #2
0
        void PaseData(int pageNum)
        {
            var client = new HtmlWeb();

            m_url = m_url.TrimEnd('/') + "/article/list/" + pageNum;
            var Node = client.Load(m_url);

            if (pageNum == 1)
            {
                string html = Node.DocumentNode.InnerHtml;
                m_totalPostCount   = JsUtil.GetJsNumVariable(html, @"var\slistTotal\s=\s\d{1,3}");
                m_perPagePostCount = JsUtil.GetJsNumVariable(html, @"var\spageSize\s=\s\d{1,3}");
                m_pageCount        = m_totalPostCount / m_perPagePostCount + (m_totalPostCount % m_perPagePostCount > 0 ? 1 : 0);
            }

            var postNodes = Node.DocumentNode.SelectNodes(PerPageArticalList);

            if (postNodes != null)
            {
                int index = 0;
                m_articleList.Clear();
                foreach (var item in postNodes)
                {
                    var doc = new HtmlDocument();
                    doc.LoadHtml(item.InnerHtml);

                    var titleNode = doc.DocumentNode.SelectSingleNode(Title);
                    var timeNode  = doc.DocumentNode.SelectSingleNode(WriteTime);

                    Article       article = new Article();
                    StringBuilder builder = new StringBuilder(titleNode.InnerText);
                    builder.Replace("\n", "");
                    builder.Replace(" ", "");
                    article.Title = builder.ToString();
                    article.Time  = timeNode.InnerText;
                    article.Link  = titleNode.Attributes["href"].Value;
                    article.Id    = GetIdByUrl(article.Link);
                    article.Index = index;
                    m_articleList.Add(article);
                    ++index;
                }
            }
        }