webBrowser控件獲得html的table數據,包括Iframe


本文章主要是講WebBrowser控件,獲得html里面table的數據。

先下載一個mshtml.dll

主要邏輯如下:

//得到table的對象
IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2;
IHTMLElementCollection tables = (IHTMLElementCollection)document.all.tags("TABLE");
if (tables.item() == null)
{
//根據franme的name得到對象
HtmlDocument htmlDoc = webBrowser1.Document;
htmlDoc = webBrowser1.Document.Window.Frames["frmRpt"].Document;
string frameHtml = webBrowser1.Document.Window.Frames["frmRpt"].Document.Body.InnerHtml;

//得到所有的franme對象
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 = table.rows;//因為TH標簽是屬於表格的表頭信息;
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;//因為TH標簽是屬於表格的表頭信息;
foreach (IHTMLElement th in tts)
{
foreach (IHTMLElement td in th.children)
{
string ts = td.innerHTML;
}
}
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM