T
Taylor
I was pleased to find this that I could easily access all the links in a
page using this construct:
IHTMLDocument2 d = (IHTMLDocument2) ie.Document;
IHTMLElementCollection links = d.links;
but disappointed to find I couldn't do the same to get all my tables (using
something like d.tables). Instead I'm resorting to the naive approach of
iterating thru d.all casting to a table and picking out the objects that
didn't turn to null.
I realize its horribly inefficient to cast every object to a table and
checking for hits. Can you advise?
Here is the naive approach which is very slow:
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object o = System.Reflection.Missing.Value;
object url = "file://" + Path.Combine(Directory.GetCurrentDirectory(),
@"..\..\test\test1.html");
ie.Navigate2(ref url,ref o,ref o,ref o,ref o);
while(ie.Busy){Thread.Sleep(2);}
IHTMLDocument2 d = (IHTMLDocument2) ie.Document;
IHTMLElementCollection all = d.all;
foreach (object el in all)
{
HTMLTableClass t = el as HTMLTableClass;
if(t!=null)
{
if( 3 == t.cells.length)
{
foreach(HTMLTableRow c in t.rows)
{
Console.WriteLine(c.innerText);
}
}
}
}
page using this construct:
IHTMLDocument2 d = (IHTMLDocument2) ie.Document;
IHTMLElementCollection links = d.links;
but disappointed to find I couldn't do the same to get all my tables (using
something like d.tables). Instead I'm resorting to the naive approach of
iterating thru d.all casting to a table and picking out the objects that
didn't turn to null.
I realize its horribly inefficient to cast every object to a table and
checking for hits. Can you advise?
Here is the naive approach which is very slow:
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();
object o = System.Reflection.Missing.Value;
object url = "file://" + Path.Combine(Directory.GetCurrentDirectory(),
@"..\..\test\test1.html");
ie.Navigate2(ref url,ref o,ref o,ref o,ref o);
while(ie.Busy){Thread.Sleep(2);}
IHTMLDocument2 d = (IHTMLDocument2) ie.Document;
IHTMLElementCollection all = d.all;
foreach (object el in all)
{
HTMLTableClass t = el as HTMLTableClass;
if(t!=null)
{
if( 3 == t.cells.length)
{
foreach(HTMLTableRow c in t.rows)
{
Console.WriteLine(c.innerText);
}
}
}
}