本节谈谈获得网页上表格的信息
直接上代码:
Private Sub Button7_Click(sender As Object,e As EventArgs) Handles Button7.Click Dim doc As mshtml.HTMLDocument doc = wbMain.Document.DomDocument Dim tab As mshtml.HTMLTable tab = doc.getElementsByTagName("table").item(0) Dim myrow As mshtml.HTMLTableRow myrow = tab.rows.item(0) Dim mycell As mshtml.HTMLTableCell mycell = myrow.cells.item(0) txtInfo.Text = "表格中第一行第一个数据:" & mycell.innerText End Sub
看看运行结果:
Private Sub Button7_Click(sender As Object,e As EventArgs) Handles Button7.Click Dim doc As mshtml.HTMLDocument doc = wbMain.Document.DomDocument Dim tab As mshtml.HTMLTable tab = doc.getElementsByTagName("table").item(0) Dim myrow As mshtml.HTMLTableRow myrow = tab.rows.item(0) Dim mycell As mshtml.HTMLTableCell mycell = myrow.cells.item(0) 'txtInfo.Text = "表格中第一行第一个数据:" & mycell.innerText txtInfo.Text = "表格中第一行第一个数据:" & mycell.innerHTML End Sub
运行结果:
这下看出来了。
tab = doc.getElementsByTagName("table").item(0)
Private Sub Button7_Click(sender As Object,e As EventArgs) Handles Button7.Click Dim doc As mshtml.HTMLDocument doc = wbMain.Document.DomDocument Dim tab As mshtml.HTMLTable tab = doc.getElementsByTagName("table").item(0) Dim myrow As mshtml.HTMLTableRow myrow = tab.rows.item(0) Dim mycell As mshtml.HTMLTableCell mycell = myrow.cells.item(0) 'txtInfo.Text = "表格中第一行第一个数据:" & mycell.innerText txtInfo.Text = "表格中第一行第一个数据:" & mycell.innerHTML mycell.innerText = "abcdefg" End Sub
运行结果:
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看 vb.net 教程 目录