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;
}
}
}
}

转载于:https://www.cnblogs.com/xiaoye2015/p/4832557.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值