
如何使用webbrowser实现html表格操作
3个回答
2016-07-26 · 百度知道合伙人官方认证企业
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注

展开全部
使用webbrowser实现html表格操作需要引入mshtml.dll这个链接库。
1、比如有如下表格代码:
<table width="100%" >
<tr style="background-color:#c9e4ff; line-height: 25px;">
<th width="5%">序号</th>
<th width="15%">违章时间</th>
<th width="20%">违章地点</th>
<th width="40%">违章行为</th>
<th width="10%">执行机关</th>
<th width="10%">是否处理</th>
</tr>
</table>
2、用mshtml.dll提供的方法解析:
IHTMLDocument2 document = webbrower.Document.DomDocument as IHTMLDocument2;
IHTMLElementCollection tables = (IHTMLElementCollection)document.all.tags("TABLE");
foreach (IHTMLTable table in tables)
{
IHTMLTableSection tts= table.tHead;//因为TH标签是属于表格的表头信息;
foreach(IHTMLElement th in tts.rows)
{
System.Diagnostics.Debug.WriteLine(th.innerText)//遍历输出内容
}
}
1、比如有如下表格代码:
<table width="100%" >
<tr style="background-color:#c9e4ff; line-height: 25px;">
<th width="5%">序号</th>
<th width="15%">违章时间</th>
<th width="20%">违章地点</th>
<th width="40%">违章行为</th>
<th width="10%">执行机关</th>
<th width="10%">是否处理</th>
</tr>
</table>
2、用mshtml.dll提供的方法解析:
IHTMLDocument2 document = webbrower.Document.DomDocument as IHTMLDocument2;
IHTMLElementCollection tables = (IHTMLElementCollection)document.all.tags("TABLE");
foreach (IHTMLTable table in tables)
{
IHTMLTableSection tts= table.tHead;//因为TH标签是属于表格的表头信息;
foreach(IHTMLElement th in tts.rows)
{
System.Diagnostics.Debug.WriteLine(th.innerText)//遍历输出内容
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
调用JS方法
HTMLWindow2 win = (IHTMLWindow2)webBrowser.Document.Window.DomWindow;
win.execScript("", "Javascript");
function DoAdd(a, b) {
return a + b;
}
object i= webBrowser.Document.InvokeScript("DoAdd", new object[] { 1, 2 });
int sum = Convert.ToInt32(i);
HTMLWindow2 win = (IHTMLWindow2)webBrowser.Document.Window.DomWindow;
win.execScript("", "Javascript");
function DoAdd(a, b) {
return a + b;
}
object i= webBrowser.Document.InvokeScript("DoAdd", new object[] { 1, 2 });
int sum = Convert.ToInt32(i);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2016-07-11 · 百度知道合伙人官方认证企业
兄弟连教育成立于2006年,11年来专注IT职业教育,是国内专业的IT技术培训学校。2016年成功挂牌新三板(股票代码:839467)市值过亿。开设专注程序员培训专注php、Java、UI、云计算、Python、HTML5、
向TA提问
关注

展开全部
调用JS方法
HTMLWindow2 win = (IHTMLWindow2)webBrowser.Document.Window.DomWindow;
win.execScript("", "Javascript");
function DoAdd(a, b) {
return a + b;
}
object i= webBrowser.Document.InvokeScript("DoAdd", new object[] { 1, 2 });
int sum = Convert.ToInt32(i);
HTMLWindow2 win = (IHTMLWindow2)webBrowser.Document.Window.DomWindow;
win.execScript("", "Javascript");
function DoAdd(a, b) {
return a + b;
}
object i= webBrowser.Document.InvokeScript("DoAdd", new object[] { 1, 2 });
int sum = Convert.ToInt32(i);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询