Пример #1
0
        public static List<GeneralBlock> GetBlock(string content, string tag, string id, string name, string cls, string exName, string exValue, string value = "value")
        {
            HtmlDocument doc = new HtmlDocument();
            doc.OptionWriteEmptyNodes = true;
            doc.LoadHtml(content);

            string condition = "";

            if (id != "")
                condition += "@id='" + id + "'";

            if (name != "" && condition == "")
                condition += "@name='" + name + "'";
            else if (name != "")
                condition += " and @name='" + name + "'";

            if (cls != "" && condition == "")
                condition += "@class='" + cls + "'";
            else if (cls != "")
                condition += " and @class='" + cls + "'";

            if (exName != "" && condition == "")
                condition += "@" + exName + "='" + exValue + "'";
            else if (exValue != "")
                condition += " and @" + exName + "='" + exValue + "'";

            if (condition != "")
                condition = "[" + condition + "]";

            List<GeneralBlock> blocks = new List<GeneralBlock>();
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//" + tag + condition);
            if (nodes == null)
                return blocks;

            foreach (HtmlNode node in nodes)
            {
                GeneralBlock b = new GeneralBlock();
                b.cls = node.GetAttributeValue("class", "");
                b.id = node.GetAttributeValue("id", "");
                //if (node.InnerHtml == "")
                //{
                //    b.innerHtml = node.ParentNode.InnerHtml;
                //    b.innerText = node.ParentNode.InnerText;
                //}
                //else
                //{
                    b.innerHtml = node.OuterHtml;
                    b.innerText = node.InnerText;
                //}
                b.name = node.GetAttributeValue("name", "");
                b.value = node.GetAttributeValue(value, ""); ;
                blocks.Add(b);
            }
            return blocks;
        }
Пример #2
0
 public static Channel ParseChannel(GeneralBlock c)
 {
     try
     {
         Channel ch = new Channel();
         ch.id = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "id").value);
         ch.name = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "name").value);
         ch.description = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "channel_description").value);
         ch.web = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "link").value);
         ch.country = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "country").value);
         ch.is_stream = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "stream_type").value);
         ch.stream = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "channel_link").value);
         ch.channel_type = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "video_type").value);
         ch.image_url = Utility.URLDecode(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "logo_path").value);
         if (ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "rating").value != "")
             ch.rating = double.Parse(ParserLib.GetBlockSingle(c.innerHtml, "channel", "", "", "", "", "", "rating").value);
         return ch;
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     return null;
 }