Example #1
0
        public AppInfo WandoujiaAppDetailUnitTest()
        {
            var rule = new SpliderRule()
            {
                ContentXPath = "//dl[@class='infos-list']",
                EachXPath    = "",
                Url          = "",
                RuleFields   = new List <RuleField>()
                {
                    new RuleField()
                    {
                        DisplayName = "Company", XPath = "//span[@class='dev-sites']", Attribute = "", IsFirstInnerText = false
                    },
                    //new RuleField(){ DisplayName="Name",XPath="div[@class='app-desc']/h2/a", IsFirstInnerText=true },
                    //new RuleField(){ DisplayName="URL",XPath="a[@class='detail-check-btn']",Attribute="href", IsFirstInnerText=false },
                }
            };
            var    splider             = new AppsSplider();
            string fileName            = @"E:\DevProjects\html-agility-pack\CsharpFanDemo-fork\CsharpFanDemo\Demo.DataSplider\testfiles\detailpage.html";
            List <SpliderContent> list = splider.GetByRuleFromFile(rule, fileName);

            AppInfo appInfo = new AppInfo();

            foreach (var item in list)
            {
                var msg = string.Empty;
                int id  = 0;
                item.Fields.ForEach(M =>
                {
                    switch (M.DisplayName)
                    {
                    case "Company":
                        appInfo.Company = M.Value;
                        break;

                    case "Description":
                        appInfo.Description = M.Value;
                        break;

                    case "URL":
                        appInfo.URL = M.Value;
                        break;

                    default:
                        break;
                    }
                    msg += $"{M.DisplayName}:{M.Value}     ";
                });
                Console.WriteLine(msg);
            }
            return(appInfo);
        }
Example #2
0
        public List <AppInfo> WandoujiaAppList(string content)
        {
            var rule = new SpliderRule()
            {
                //ContentXPath = "//ul[@id='j-tag-list']",//这是从网页上找。
                ContentXPath = @"/", //这是从网页上找。
                EachXPath    = "li[@class='card']",
                Url          = "",   //豌豆荚 某个分类下的应用列表。url应该作为一个参数输入。
                RuleFields   = new List <RuleField>()
                {
                    new RuleField()
                    {
                        DisplayName = "Id", XPath = "a[@class='detail-check-btn']", Attribute = "data-app-id", IsFirstInnerText = false
                    },
                    new RuleField()
                    {
                        DisplayName = "Name", XPath = "div[@class='app-desc']/h2/a", IsFirstInnerText = true
                    },
                    new RuleField()
                    {
                        DisplayName = "URL", XPath = "a[@class='detail-check-btn']", Attribute = "href", IsFirstInnerText = false
                    },
                    //new RuleField(){ DisplayName="图标",XPath="p[@class='tem']/span",Attribute="", IsFirstInnerText=true },
                    new RuleField()
                    {
                        DisplayName = "InstallCount", XPath = "div[@class='app-desc']/div[@class='meta']/span[@class='install-count']", Attribute = "", IsFirstInnerText = true
                    },
                }
            };
            var splider = new AppsSplider();
            List <SpliderContent> list = splider.GetByRule(rule, content);
            //打印出来
            List <AppInfo> appList = new List <AppInfo>();

            //AppList appList = new AppList();
            foreach (var item in list)
            {
                AppInfo appInfo = new AppInfo();
                var     msg     = string.Empty;
                int     id      = 0;
                item.Fields.ForEach(M =>
                {
                    switch (M.DisplayName)
                    {
                    case "Id":
                        appInfo.Id = M.Value;
                        break;

                    case "Name":
                        appInfo.Name = M.Value;
                        break;

                    case "URL":
                        appInfo.URL = M.Value;
                        break;

                    default:
                        break;
                    }
                    appList.Add(appInfo);
                    msg += $"{M.DisplayName}:{M.Value}     ";
                });
                Console.WriteLine(msg);
            }
            return(appList);
        }