本文整理汇总了C#中HtmlAgilityPack.HtmlNodeCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlNodeCollection.Add方法的具体用法?C# HtmlNodeCollection.Add怎么用?C# HtmlNodeCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HtmlAgilityPack.HtmlNodeCollection
的用法示例。
在下文中一共展示了HtmlNodeCollection.Add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
/// <summary>
/// Run xpath from html or node
/// </summary>
public List<List<KeyValuePair<string, object>>> run(HtmlNode node)
{
Factory.Instance.iInfo(string.Format("Running xpathCollection id : {0}", rule.id));
HtmlNodeCollection nodes = new HtmlNodeCollection(node);
HtmlNodeCollection n2 = node.SelectNodes(rule.xpath);
if (n2 != null)
{
foreach (HtmlNode n in n2)
nodes.Add(n);
}
//run
if (node != null)
{
foreach (HtmlNode n in nodes)
{
List<KeyValuePair<string, object>> last_val = null;
if (rule.xpathSingle != null)
{
XPathSingle xs = new XPathSingle(rule.xpathSingle, last_val);
last_val = (List<KeyValuePair<string, object>>)xs.Run(n);
res.Add(last_val);
}
}
}
return res;
}
示例2: SelectNodes
/// <summary>
/// Selects a list of nodes matching the <see cref="XPath"/> expression.
/// </summary>
/// <param name="xpath">The XPath expression.</param>
/// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns>
public HtmlNodeCollection SelectNodes(string xpath)
{
var list = new HtmlNodeCollection(null);
var nav = new HtmlNodeNavigator(OwnerDocument, this);
var it = nav.Select(xpath);
while (it.MoveNext())
{
var n = (HtmlNodeNavigator)it.Current;
list.Add(n.CurrentNode);
}
return list.Count == 0 ? null : list;
}
示例3: SelectNodes
/// <summary>
/// Selects a list of nodes matching the <see cref="XPath"/> expression.
/// </summary>
/// <param name="xpath">The XPath expression.</param>
/// <returns>An <see cref="HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="XPath"/> query, or <c>null</c> if no node matched the XPath expression.</returns>
public HtmlNodeCollection SelectNodes(string xpath)
{
HtmlNodeCollection list = new HtmlNodeCollection(null);
HtmlNodeNavigator nav = new HtmlNodeNavigator(OwnerDocument, this);
XPathNodeIterator it = nav.Select(xpath);
while (it.MoveNext())
{
HtmlNodeNavigator n = (HtmlNodeNavigator)it.Current;
list.Add(n.CurrentNode);
}
return list;
}
示例4: GetLinksReturnsCorrectValue
public void GetLinksReturnsCorrectValue()
{
// check that there is no exception and it returns empty list
Assert.Equal(0, GetLinks(null).Count);
// check with the predefined html
HtmlDocument doc = new HtmlDocument();
Page page = PageDocumentTestHelper.GetTestPage(3);
doc.LoadHtml(page.Content);
HtmlNodeCollection col = new HtmlNodeCollection(doc.DocumentNode);
foreach (HtmlNode link in doc.DocumentNode.SelectNodes("//a[@href]"))
col.Add(link);
Assert.Equal(129, GetLinks(col).Count);
}
示例5: GoToPageAndGetTableNodes
private void GoToPageAndGetTableNodes(string startUrl, string pageUrl, HtmlNodeCollection allTableNodesForMonth)
{
string url = startUrl + pageUrl;
bool haveNextPage = true;
do
{
// Get all links for the first page
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(url);
HtmlNodeCollection tableNodes = doc.DocumentNode.SelectNodes("//tr[@class='roweven']|//tr[@class='rowodd']");
foreach (var node in tableNodes)
{
allTableNodesForMonth.Add(node);
}
// Get links for the other pages
HtmlNode nextPage = null;
if (doc.DocumentNode.SelectNodes("//td[@class='pagenumber']") != null)
{
nextPage = doc.DocumentNode.SelectNodes("//td[@class='pagenumber']").LastOrDefault();
}
if (nextPage != null)
{
var linkNode = nextPage.FirstChild;
if (linkNode.Attributes["href"] != null)
{
url = startUrl + "/cgi-bin/rechtsprechung/" + linkNode.Attributes["href"].Value;
url = url.Replace("amp;", string.Empty);
}
else
{
haveNextPage = false;
}
}
else
{
haveNextPage = false;
}
}
while (haveNextPage);
}
示例6: SelectNodes
/// <summary>
/// Selects a list of nodes matching the XPath expression.
/// </summary>
/// <param name="xpath">The XPath expression.</param>
/// <returns>An HtmlNodeCollection containing a collection of nodes matching the XPath query, or null if no node matched the XPath expression.</returns>
public HtmlNodeCollection SelectNodes(string xpath)
{
HtmlNodeCollection list = new HtmlNodeCollection(null);
try
{
HtmlNodeNavigator nav = new HtmlNodeNavigator(_ownerdocument, this);
XPathNodeIterator it = nav.Select(xpath);
while (it.MoveNext())
{
HtmlNodeNavigator n = (HtmlNodeNavigator)it.Current;
list.Add(n.CurrentNode);
}
}
catch (Exception ex)
{
O2.Kernel.ExtensionMethods.Logging_ExtensionMethods.log(ex, "in HtmlNodeCollection SelectNodes");
}
//DC removed this so that we get an empty list when there are no matching nodes
//if (list.Count == 0)
//{
// return null;
//}
return list;
}
示例7: get_gallery_items_nodes
public override HtmlNodeCollection get_gallery_items_nodes(HtmlNode root)
{
var node_items = new HtmlNodeCollection (null);
var items = base.get_gallery_items_nodes (root);
foreach (var item in items) {
// skip signatures
if (item.Attributes.Contains ("class") && item.Attributes ["class"].Value.Contains ("signature")) {
continue;
}
var nodes = item.SelectNodes (".//a");
if (nodes != null) {
foreach (var node in nodes) {
node_items.Add (node);
}
}
}
return node_items;
}
示例8: FinalizeHtmlDocument
private void FinalizeHtmlDocument(IList<ArelleColumnSection> outlist)
{
var mtn = this.mainTableNode;
for (int i = 0; i < mtn.ChildNodes.Count; i++)
{
mtn.ChildNodes[i].RemoveAllChildren();
var row = new HtmlNodeCollection(mtn.ChildNodes[i]);
foreach (var item in outlist[i].DynamicColumns)
{
row.Add(item);
}
foreach (var item in outlist[i].NewStaticColumns)
{
row.Add(item);
}
mtn.ChildNodes[i].AppendChildren(row);
}
}
示例9: SelectNodes
/// <summary>
/// Selects a list of nodes matching the <see cref="P:HtmlAgilityPack.HtmlNode.XPath"/> expression.
///
/// </summary>
/// <param name="xpath">The XPath expression.</param>
/// <returns>
/// An <see cref="T:HtmlAgilityPack.HtmlNodeCollection"/> containing a collection of nodes matching the <see cref="P:HtmlAgilityPack.HtmlNode.XPath"/> query, or <c>null</c> if no node matched the XPath expression.
/// </returns>
public HtmlNodeCollection SelectNodes(string xpath)
{
HtmlNodeCollection htmlNodeCollection = new HtmlNodeCollection((HtmlNode) null);
XPathNodeIterator xpathNodeIterator = new HtmlNodeNavigator(this.OwnerDocument, this).Select(xpath);
while (xpathNodeIterator.MoveNext())
{
HtmlNodeNavigator htmlNodeNavigator = (HtmlNodeNavigator) xpathNodeIterator.Current;
htmlNodeCollection.Add(htmlNodeNavigator.CurrentNode);
}
if (htmlNodeCollection.Count == 0)
return (HtmlNodeCollection) null;
return htmlNodeCollection;
}