Exemplo n.º 1
0
        /// <summary>
        /// 获取表头中的所有的input和select标签的数据
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static Dictionary <int, List <MYDataHead> > GetHeadData(HtmlAgilityPack.HtmlDocument doc)
        {
            var data = new Dictionary <int, List <MYDataHead> >();

            //表头
            Dictionary <int, HtmlAgilityPack.HtmlNodeCollection> theadOfInputAndSelect = AnalyticHTML.GetTheadOfInputAndSelect(doc);

            //遍历通道
            foreach (var item in theadOfInputAndSelect.Keys)
            {
                HtmlAgilityPack.HtmlNodeCollection body = theadOfInputAndSelect[item];
                List <MYDataHead> list = new List <MYDataHead>();
                foreach (var b in body)
                {
                    MYDataHead mydata = new MYDataHead();
                    mydata.id   = b.Attributes["id"].Value;
                    mydata.name = b.Attributes["name"].Value;

                    if (b.Name == "input")
                    {
                        if (b.Attributes["value"] != null)
                        {
                            mydata.value = b.Attributes["value"].Value;
                        }
                    }
                    else if (b.Name == "select")
                    {
                        var nodes = b.ChildNodes
                                    .Where(w => (w.Name == "option" && w.Attributes["selected"] != null))
                                    .Select(s => s.Attributes["value"].Value).FirstOrDefault();

                        if (null == (nodes))
                        {
                            mydata.value = b.ChildNodes
                                           .Where(w => (w.Name == "option"))
                                           .Select(s => s.Attributes["value"].Value).First();
                        }
                        else
                        {
                            mydata.value = nodes;
                        }
                    }

                    list.Add(mydata);
                }
                data.Add(item, list);
            }
            return(data);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取底部不确定标签
        /// </summary>
        /// <param name="doc"></param>
        /// <returns></returns>
        public static HeadValue GetBuDueDingDu_DiBu(HtmlAgilityPack.HtmlDocument doc)
        {
            var    buDueDingDu_DiBu = new HeadValue();
            string xpath            = @"//tbody[@class='dibubuque1']/tr/td/input[@type='text'] | //tbody[@class='dibubuque1']/tr/td/select";
            var    thead            = doc.DocumentNode.SelectNodes(xpath);

            if (thead != null)
            {
                List <MYDataHead> list = new List <MYDataHead>();
                foreach (var b in thead)
                {
                    MYDataHead mydata = new MYDataHead();
                    mydata.id   = b.Attributes["id"].Value;
                    mydata.name = b.Attributes["name"].Value;

                    if (b.Name == "input")
                    {
                        if (b.Attributes["value"] != null)
                        {
                            mydata.value = b.Attributes["value"].Value;
                        }
                    }
                    else if (b.Name == "select")
                    {
                        var nodes = b.ChildNodes
                                    .Where(w => (w.Name == "option" && w.Attributes["selected"] != null))
                                    .Select(s => s.Attributes["value"].Value).FirstOrDefault();

                        if (null == (nodes))
                        {
                            mydata.value = b.ChildNodes
                                           .Where(w => (w.Name == "option"))
                                           .Select(s => s.Attributes["value"].Value).First();
                        }
                        else
                        {
                            mydata.value = nodes;
                        }
                    }

                    list.Add(mydata);
                }
                buDueDingDu_DiBu.Data  = list;
                buDueDingDu_DiBu.Count = list.Count / 3;
            }


            return(buDueDingDu_DiBu);
        }