Example #1
0
        private static List <POCO_Category> InitB(POCO_Category parentModel, HtmlNode node)
        {
            int idIndex = Convert.ToInt32(parentModel.Id) + 1;
            List <POCO_Category> bList = new List <POCO_Category>();

            var xNodes = node.SelectNodes("./div").ToList();

            foreach (var xNode in xNodes)
            {
                var           cateModel = xNode.SelectSingleNode("./div[1]/a");
                POCO_Category bModel    = new POCO_Category()
                {
                    Id     = ToLevelCode(idIndex),
                    PId    = parentModel.Id,
                    Code   = $"{parentModel.Code}_{ToLevelCode(idIndex)}",
                    Name   = cateModel.InnerText,
                    Url    = $"https:{cateModel.GetAttributeValue("href")}",
                    Levels = 2
                };
                bList.Add(bModel);

                var clist = InitC(bModel, xNode.SelectSingleNode("./div[2]"));
                bList.AddRange(clist);
                idIndex = idIndex + clist.Count + 1;
            }

            return(bList);
        }
Example #2
0
        private static List <POCO_Category> InitC(POCO_Category parentModel, HtmlNode node)
        {
            int idIndex = Convert.ToInt32(parentModel.Id) + 1;
            List <POCO_Category> cList = new List <POCO_Category>();

            HtmlNodeCollection xNodes = node.SelectNodes("./a");

            if (xNodes != null && xNodes.Count > 0)
            {
                foreach (var xNode in xNodes)
                {
                    POCO_Category cModel = new POCO_Category()
                    {
                        Id     = ToLevelCode(idIndex),
                        PId    = parentModel.Id,
                        Code   = $"{parentModel.Code}_{ToLevelCode(idIndex)}",
                        Name   = xNode.InnerText,
                        Url    = $"https:{xNode.GetAttributeValue("href")}",
                        Levels = 3
                    };
                    cList.Add(cModel);
                    idIndex += 1;
                }
            }

            return(cList);
        }
Example #3
0
        private static List <POCO_Category> CombineA_B_C()
        {
            List <POCO_Category> AList = new List <POCO_Category>();

            int idIndex = 1;

            foreach (HtmlNode xNode in InitA())
            {
                POCO_Category aModel = new POCO_Category()
                {
                    Id     = ToLevelCode(idIndex),
                    PId    = "000",
                    Levels = 1,
                    Code   = ToLevelCode(idIndex),
                    Name   = xNode.SelectSingleNode("./h2").InnerText
                };
                AList.Add(aModel);

                var blist = InitB(aModel, xNode);
                AList.AddRange(blist);
                idIndex = idIndex + blist.Count + 1;
            }

            return(AList);
        }