The WebBrowser control obtains the table data for HTML, including the IFRAME

Source: Internet
Author: User

This article is mainly about WebBrowser control, get the data of table in HTML.

Download a Mshtml.dll First

The main logic is as follows:

Get the object of table
IHTMLDocument2 document = WebBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLElementCollection tables = (ihtmlelementcollection) document.all.tags ("TABLE");
if (tables.item () = = null)
{
Gets the object according to the name of Franme
HTMLDocument htmldoc = webbrowser1.document;
Htmldoc = webbrowser1.document.window.frames["Frmrpt"]. Document;
String framehtml = webbrowser1.document.window.frames["Frmrpt"]. Document.Body.InnerHtml;

//Get all Franme objects
HTMLDocument doc = (htmldocument) webBrowser1.Document.DomDocument;
Object J;
for (int i = 0; i < doc.parentWindow.frames.length; i++)
{
J = i;
HTMLWindow2 frame = Doc.parentWindow.frames.item (ref j) as HTMLWindow2;
//if (Frame.name = = "Frmrpt")
//{
IHTMLElementCollection tabless = (ihtmlelementcollection) Frame.document.all.tags ("TABLE");
if (tabless.item () = null)
{
foreach (ihtmltable table in tabless)
{
IHTMLElementCollection TTS = TA ble.rows;//because th tag is the table header information that belongs to the table;
foreach (IHTMLElement th in TTS)
{
foreach (IHTMLElement td in Th.children)
{
String ts = td.innerhtml;
}
}
}
//}

}
}
}
Else
{
foreach (ihtmltable table in tables)
{
IHTMLElementCollection TTS = table.rows;//because th tag is the table header information belonging to the table;
foreach (IHTMLElement th in TTS)
{
foreach (IHTMLElement td in Th.children)
{
string ts = td.innerhtml;
}
}
}
}

The WebBrowser control obtains the table data for HTML, including the IFRAME

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.