用下面代码慢慢获取。一次性获取会很慢,红色代码慢慢注释掉,理解代码。
mark 获取网页数据
Dim url As String = "http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2013/"
For i As Integer = 11 To 65
Dim web As new System.Windows.Forms.WebBrowser
web.Navigate(url & i & ".html")
Do While web.ReadyState <> 4
Application.DoEvents
Loop
Dim trs = web.Document.GetElementsByTagName("table")(4).GetElementsByTagName("tr")
For j As Integer = 1 To trs.count - 1
Dim tr = trs(j)
Dim tds = tr.GetElementsByTagName("td")
output.show(tds(0).innerText)
output.show(tds(1).innerText)
output.show(tds(1).GetElementsByTagName("a")(0).GetAttribute("href"))
Dim web1 As new System.Windows.Forms.WebBrowser
web1.Navigate(tds(1).GetElementsByTagName("a")(0).GetAttribute("href"))
Do While web1.ReadyState <> 4
Application.DoEvents
Loop
Dim trs1 = web1.Document.GetElementsByTagName("table")(4).GetElementsByTagName("tr")
For j1 As Integer = 1 To trs1.count - 1
Dim tr1 = trs1(j1)
Dim tds1 = tr1.GetElementsByTagName("td")
output.show(tds1(0).innerText)
output.show(tds1(1).GetElementsByTagName("a")(0).GetAttribute("href"))
Dim web2 As new System.Windows.Forms.WebBrowser
web2.Navigate(tds1(1).GetElementsByTagName("a")(0).GetAttribute("href"))
Do While web2.ReadyState <> 4
Application.DoEvents
Loop
Dim trs2 = web2.Document.GetElementsByTagName("table")(4).GetElementsByTagName("tr")
For j2 As Integer = 1 To trs2.count - 1
Dim tr2 = trs2(j2)
Dim tds2 = tr2.GetElementsByTagName("td")
output.show(tds2(0).innerText)
output.show(tds2(1).GetElementsByTagName("a")(0).GetAttribute("href"))
Dim web3 As new System.Windows.Forms.WebBrowser
web3.Navigate(tds2(1).GetElementsByTagName("a")(0).GetAttribute("href"))
Do While web3.ReadyState <> 4
Application.DoEvents
Loop
Dim trs3 = web3.Document.GetElementsByTagName("table")(4).GetElementsByTagName("tr")
For j3 As Integer = 1 To trs3.count - 1
Dim tr3 = trs3(j3)
Dim tds3 = tr3.GetElementsByTagName("td")
output.show(tds3(0).innerText)
output.show(tds3(1).innerText)
output.show(tds3(2).innerText)
Next
'web3 = Nothing
web3.Dispose
return ""
Next
'web2 = Nothing
web2.Dispose
return ""
Next
'web1 = Nothing
web1.Dispose
return ""
Next
web.Dispose
return ""
Next