Dim url As String = "http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2013/"
For i As Integer = 13 To 14
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) '二级ID
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) '三级ID
output.show(tds1(1).innerText) '三级
' output.show(tds1(1).GetElementsByTagName("a")(0).GetAttribute("href"))
If tds1(1).GetElementsByTagName("a").Count > 0 Then
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) '四级ID
output.show(tds2(1).innerText) '四级
' output.show(tds2(1).GetElementsByTagName("a")(0).GetAttribute("href"))
If tds2(1).GetElementsByTagName("a").Count > 0 Then
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")
Dim r As Row = Tables("全国行政区").AddNew
r("省级ID") = i
r("二级ID") = tds(0).innerText
r("三级ID") = tds1(0).innerText
r("四级ID") = tds2(0).innerText
r("五级ID") = tds3(0).innerText
r("二级") = tds(1).innerText
r("三级") = tds1(1).innerText
r("四级") = tds2(1).innerText
r("五级") = tds3(2).innerText
output.show(tds3(0).innerText) '五级ID
' output.show(tds3(1).innerText) '五级
output.show(tds3(2).innerText)
Next
'web3 = Nothing
web3.Dispose
' Return ""
Else
Dim r As Row = Tables("全国行政区").AddNew
r("省级ID") = i
r("二级ID") = tds(0).innerText
r("三级ID") = tds1(0).innerText
r("四级ID") = tds2(0).innerText
r("二级") = tds(1).innerText
r("三级") = tds1(1).innerText
r("四级") = tds2(1).innerText
End If
Next
'web2 = Nothing
web2.Dispose
' Return ""
Else
Dim r As Row = Tables("全国行政区").AddNew
r("省级ID") = i
r("二级ID") = tds(0).innerText
r("三级ID") = tds1(0).innerText
r("二级") = tds(1).innerText
r("三级") = tds1(1).innerText
End If
Next
'web1 = Nothing
web1.Dispose
' Return ""
Next
web.Dispose
' Return ""
Next
此主题相关图片如下:微信截图_20180115181346.png
此主题相关图片如下:qq截图20180115173841.png
正常的五级分类为什么会报错,哪位老师帮忙看下。。。