This project has moved. For the latest updates, please go here.

Parse for a known Table

Topics: User Forum
Oct 6, 2006 at 11:11 AM
Hi All,

just starting to work with the Agility-Pack i have a (simple?) Question. Via:

HtmlAgilityPack.HtmlWeb oWeb = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument oDoc = oWeb.Load(sURL);

i get the requested Htmldocument. To find a specific table, i iterate through the Elements/Nodes and there Childnotes as long as i have the wanted Node representing the Table.

This Iteration is not so lovely - as well as i know what Table i want and i have an Attribute, in this case a class="Hello". In Htmlcode as:

<table class="Hello" border=0>

Is it possible to search directly for an specific Node? For Example something like this:


Thanks in Advance !!

Jan Waiz

Oct 13, 2006 at 1:35 AM
Take a look at SelectNodes() and SelectSingleNode() with an XPATH:

Oct 18, 2006 at 12:53 PM
Thanks for your Replay - but i did not have Success...

Take this Url for Example:
and search for that Table as class="ratesContent"

I use it as:
HtmlAgilityPack.HtmlNode TableNode = oRootNode.SelectSingleNode("//table@class=\"ratesContent\"");

I get an Error as this:
'//table@class="ratesContent"' is an unguilty Token

Any Idea ?

Thanks a lot in Advance !!!

Jan Waiz
Oct 18, 2006 at 12:55 PM
Sorry - here is the complete code:

HtmlAgilityPack.HtmlWeb oWeb = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument oDoc = oWeb.Load(sURL);

HtmlAgilityPack.HtmlNode oRootNode = oDoc.DocumentNode;

if (oRootNode == null)
{ throw new Exception("RootNode not found..."); }

HtmlAgilityPack.HtmlNode oTableNode = oRootNode.SelectSingleNode("//table@class=\"ratesContent\"");
Nov 3, 2006 at 2:21 PM
Looks like CodePlex is turning his text into an href.

In XPath, you place brackets '' and '' around your matching expression for a node.

Where you see hyperlinks in the code he provided, put brackets around the text that is hyperlinked.
Nov 3, 2006 at 2:22 PM
Ha, it did it to me too.


      • ***
  • *
  • *
      • ***

Anybody know if there is an escape to prevent brackets from creating links in codeplex?
Nov 3, 2006 at 2:23 PM
Seriously, codeplex's auto-formatting of character combo's is annoying.