代码如下:
Dim web As new System.Windows.Forms.WebBrowser
web.ScriptErrorsSuppressed = True
web.Navigate("http://www.gzwengan.jcy.gov.cn/gzdt/")
Do Until web.ReadyState = 4
Application.DoEvents
Loop
Dim obj = web.document.GetElementsByTagName("table")(37) '页面代码TABLE的一共有82个 含<table></table>
Dim count = obj.InnerText.Substring(1,1)
output.Show(count)
Dim str As String = ""
For i As Integer = 1 To count
Dim pg = web.Document.GetElementById("num")
pg.SetAttribute("Value", i)
Dim inputs = web.Document.GetElementsByTagName("input")
For Each input As object In inputs
If input.GetAttribute("type") = "submit" Then
input.InvokeMember("click")
Do Until web.document.GetElementsByTagName("table").count > 36
Application.DoEvents
Loop
Dim tb1s = web.document.GetElementsByTagName("table")(36) '页面代码TABLE的一共有82个 含<table></table>即从第36个<Table>开始查找
For Each tb1 As object In tb1s.GetElementsByTagName("tr")'遍历TR'
Dim sa = tb1.GetElementsByTagName("a")'获取A标签元素'
If sa.count > 0 Then
Dim a = sa(0)
str &= a.InnerHtml
str &= a.GetAttribute("href")
Dim shijian As String= (FileSys.GetName(a.GetAttribute("href")).Insert(5,"-")).Insert(8,"-")
Dim Parts() As String = shijian.Split("_")
str & =Parts(0).Remove(0,1)
End If
Next
End If
Next
Next
output.Show(str)
错误如下:
此主题相关图片如下:111.png
如果将代码去掉“下一页”所有操作代码如下:
Dim web As new System.Windows.Forms.WebBrowser
web.ScriptErrorsSuppressed = True
web.Navigate("http://www.gzwengan.jcy.gov.cn/gzdt/")
Do Until web.ReadyState = 4
Application.DoEvents
Loop
Dim obj = web.document.GetElementsByTagName("table")(37) '页面代码TABLE的一共有82个 含<table></table>
Dim count = obj.InnerText.Substring(1,1)
output.Show(count)
Dim str As String = ""
Dim tb1s = web.document.GetElementsByTagName("table")(36) '页面代码TABLE的一共有82个 含<table></table>即从第36个<Table>开始查找
For Each tb1 As object In tb1s.GetElementsByTagName("tr")'遍历TR'
Dim sa = tb1.GetElementsByTagName("a")'获取A标签元素'
If sa.count > 0 Then
Dim a = sa(0)
str &= a.InnerHtml
str &= a.GetAttribute("href")
Dim shijian As String= (FileSys.GetName(a.GetAttribute("href")).Insert(5,"-")).Insert(8,"-")
Dim Parts() As String = shijian.Split("_")
str & =Parts(0).Remove(0,1)
End If
Next
output.Show(str)
运行结果如下:
此主题相关图片如下:111.png