c# webbrowser 如何获取table中的数据

weiling6586 2009-08-28 04:38:05
c# webbrowser 如何获取table中的数据
<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>
我要获取“违章时间”几个字
...全文
961 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
bustersword 2010-12-24
  • 打赏
  • 举报
回复
使用jquery,你可以很容易获取该字符串
ttllxx 2010-12-24
  • 打赏
  • 举报
回复
俺是自己获取网页字符串,然后再对字符串操作直到获取需要的数据。
fish515 2010-12-24
  • 打赏
  • 举报
回复
找了半天,CSDN的编辑帖子的功能,没找到,基本没怎么登陆过这个网站的原因吧,还不熟,我重贴一遍修改后的代码;
//首先获取表格对象,需引入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)
{
if(th.getAttribute("width", 0).ToString() == "15%")
System.Diagnostics.Debug.WriteLine(th.innerText)//控制台输出所需内容:“违章时间”
}
}
fish515 2010-12-24
  • 打赏
  • 举报
回复
//首先获取表格对象,需引入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)//遍历输出内容
}
}
liffe 2009-08-28
  • 打赏
  • 举报
回复
bagnding

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧