当前位置: 首页>>代码示例>>C#>>正文


C# HtmlNode.Select方法代码示例

本文整理汇总了C#中HtmlAgilityPack.HtmlNode.Select方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNode.Select方法的具体用法?C# HtmlNode.Select怎么用?C# HtmlNode.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlAgilityPack.HtmlNode的用法示例。


在下文中一共展示了HtmlNode.Select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Evaluate

        private static Match[] Evaluate(HtmlDocument document, Control tb, ListBox lb, Control hb, ToolStripItem status, IEnumerable<Match> oldMatches, RichTextBox rtb)
        {
            var input = tb.Text.Trim();
            tb.ForeColor = SystemColors.WindowText;
            
            var elements = new HtmlNode[0];
            
            if (string.IsNullOrEmpty(input))
            {
                status.Text = "Ready";
                hb.Text = null;
            }
            else
            {
                try
                {
                    //
                    // Simple way to query for elements:
                    //
                    // nodes = document.DocumentNode.QuerySelectorAll(input).ToArray();
                    //
                    // However, we want to generate the human readable text and
                    // the element selector in a single pass so go the bare metal way 
                    // here to make all the parties to talk to each other.
                    //
                    
                    var generator = new SelectorGenerator<HtmlNode>(new HtmlNodeOps());
                    var helper = new HumanReadableSelectorGenerator();
                    Parser.Parse(input, new SelectorGeneratorTee(generator, helper));
                    if (document != null)
                        elements = generator.Selector(Enumerable.Repeat(document.DocumentNode, 1)).ToArray();
                    hb.Text = helper.Text;

                    status.Text = "Matches: " + elements.Length.ToString("N0");
                }
                catch (FormatException e)
                {
                    tb.ForeColor = Color.FromKnownColor(KnownColor.Red);
                    status.Text = "Error: " + e.Message;
                    hb.Text = "Oops! " + e.Message;
                }
            }
            
            if (oldMatches != null)
                Highlight(rtb, oldMatches, null, SystemColors.Info, null);
        
            lb.BeginUpdate();
            try
            {
                lb.Items.Clear();
                if (!elements.Any())
                    return new Match[0];

                var html = rtb.Text;
                var matches  = new List<Match>(elements.Length);
                foreach (var element in elements)
                {
                    var index = rtb.GetFirstCharIndexFromLine(element.Line - 1) + element.LinePosition - 1;
                    var match = _tagExpression.Match(html, index);
                    if (match.Success)
                        matches.Add(match);
                }
                
                Highlight(rtb, matches, null, Color.Yellow, null);
                
                lb.Items.AddRange(elements.Select(n => n.GetBeginTagString()).ToArray());
                
                return matches.ToArray();
            }
            finally
            {
                lb.EndUpdate();
            }
        }
开发者ID:Sword-Breaker,项目名称:fizzler,代码行数:74,代码来源:MainForm.cs


注:本文中的HtmlAgilityPack.HtmlNode.Select方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。