本文整理汇总了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();
}
}