示例#1
0
        /// <summary>
        /// 在一个一级类下面的全部二级类进行查找
        /// </summary>
        /// <param name="html"></param>
        /// <param name="parentCode"></param>
        /// <returns></returns>
        private List <TencentCategoryEntity> Second(string url, string parentCode)
        {
            string html = HttpHelper.DownloadUrl(url);
            List <TencentCategoryEntity> categoryList = new List <TencentCategoryEntity>();
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            string             path     = "//*[@id='auto-test-1']/div[1]/dl/dd";
            HtmlNodeCollection nodeList = doc.DocumentNode.SelectNodes(path);

            foreach (HtmlNode node in nodeList)
            {
                HtmlDocument htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(node.InnerHtml);

                string   codePath = "//a";
                HtmlNode codeNode = htmlDocument.DocumentNode.SelectSingleNode(codePath);
                string   href     = codeNode.Attributes["href"].Value;
                if (!string.IsNullOrWhiteSpace(href))
                {
                    href = href.Replace(";", "&");
                }

                string code = string.Empty;
                if (href != null && href.IndexOf("st=") != -1)
                {
                    href = href.Replace(";", "&");
                    code = href.Substring(href.IndexOf("st=") + 3, 4);
                }
                TencentCategoryEntity category = new TencentCategoryEntity()
                {
                    Id            = _Count++,
                    State         = 1,
                    CategoryLevel = 2,
                    Code          = code,
                    ParentCode    = parentCode
                };
                category.Name = codeNode.InnerText;
                category.Url  = href;

                categoryList.Add(category);

                if (codeNode.InnerText != "全部")
                {
                    categoryList.AddRange(this.Third($"https://ke.qq.com{href}&tuin=7e4f8b7d", code));
                }
            }
            return(categoryList);
        }
示例#2
0
        /// <summary>
        /// 在一个二级类下的全部三级类里面进行查找
        /// </summary>
        /// <param name="html"></param>
        /// <param name="parentCode"></param>
        /// <returns></returns>
        private List <TencentCategoryEntity> Third(string url, string parentCode)
        {
            string html = HttpHelper.DownloadUrl(url);
            List <TencentCategoryEntity> categoryList = new List <TencentCategoryEntity>();
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            string             path     = "//*[@id='auto-test-1']/div[1]/dl/dd";
            HtmlNodeCollection nodeList = doc.DocumentNode.SelectNodes(path);

            if (nodeList == null)
            {
            }
            foreach (HtmlNode node in nodeList)
            {
                HtmlDocument htmlDocument = new HtmlDocument();

                htmlDocument.LoadHtml(node.InnerHtml);

                string   codePath = "//a";
                HtmlNode codeNode = htmlDocument.DocumentNode.SelectSingleNode(codePath);
                string   href     = codeNode.Attributes["href"].Value;

                string code = string.Empty;
                if (href != null)
                {
                    href = href.Replace(";", "&");
                }
                if (href != null && href.IndexOf("tt=") != -1)
                {
                    href = href.Replace(";", "&");
                    code = href.Substring(href.IndexOf("tt=") + 3, 4);
                }
                TencentCategoryEntity category = new TencentCategoryEntity()
                {
                    Id            = _Count++,
                    State         = 1,
                    CategoryLevel = 3,
                    Code          = code,
                    ParentCode    = parentCode
                };
                category.Name = codeNode.InnerText;
                category.Url  = href;
                categoryList.Add(category);
            }
            return(categoryList);
        }
示例#3
0
        /// <summary>
        /// 对每一个一级类进行查找
        /// </summary>
        /// <param name="html"></param>
        /// <param name="code"></param>
        /// <param name="parentCode"></param>
        /// <returns></returns>
        private List <TencentCategoryEntity> First(string html, string parentCode)
        {
            List <TencentCategoryEntity> categoryList = new List <TencentCategoryEntity>();
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(html);
            string   namePath = "//a/h2";
            HtmlNode name     = doc.DocumentNode.SelectSingleNode(namePath);
            string   codePath = "//a";
            HtmlNode codeNode = doc.DocumentNode.SelectSingleNode(codePath);
            string   href     = codeNode.Attributes["href"].Value;

            string code = string.Empty;

            if (href != null && href.IndexOf("mt=") != -1)
            {
                href = href.Replace(";", "&");
                code = href.Substring(href.IndexOf("mt=") + 3, 4);
            }
            TencentCategoryEntity category = new TencentCategoryEntity()
            {
                Id            = _Count++,
                State         = 1,
                CategoryLevel = 1,
                Code          = code,
                ParentCode    = parentCode
            };

            category.Name = name.InnerText;
            category.Url  = href;
            categoryList.Add(category);
            if (name.InnerText != "全部")
            {
                categoryList.AddRange(this.Second($"https://ke.qq.com{href}&tuin=7e4f8b7d", code));
            }
            return(categoryList);
        }
示例#4
0
 public CourseSearch(TencentCategoryEntity _category)
 {
     category = _category;
 }