Dim web As new System.Windows.Forms.WebBrowser
web.ScriptErrorsSuppressed = True
web.Navigate("http://toutiao.com/m6051259851/")
Do Until web.ReadyState = 4
Application.DoEvents
Loop
Dim divs = web.Document.GetElementById("ColumnContainer")
For Each div As object In divs.GetElementsByTagName("div")
If div.GetAttribute("ClassName") = "pin" Then
Dim tbs = div.GetElementsByTagName("table")
Dim trs = tbs(0).GetElementsByTagName("tr")
output.show(trs(0).GetElementsByTagName("h3")(0).Innertext)
output.show(trs(1).GetElementsByTagName("div")(1).Innertext)
Dim tds = trs(2).GetElementsByTagName("td")
output.show(tds(1).innertext)
output.show(tds(2).innertext)
output.show(tds(3).innertext)
output.show("------")
End If
Next
之前的今日头条网页查值,大红袍老师利用了上面代码实现了相关数据的查值。
由于我个人理解不深透,拟参考上述写法,获取其他网页代码中的值,结果提示错误。求指导。
此主题相关图片如下:7228.tm.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 bodys = web.Document.GetElementById("fontzoom")
For Each body As object In bodys.GetElementsByTagName("body")
If body.GetAttribute("Classname") = "b14" Then
Dim tbs = body.GetElementsByTagName("table")
Dim trs = tbs(0).GetElementsByTagName("td")
output.show(trs(0).GetElementsByTagName("left")(0).Innertext)
'output.show(trs(1).GetElementsByTagName("href")(1).Innertext)
'Dim tds = trs(1).GetElementsByTagName("td")
'output.show(tds(1).innertext)
'output.show(tds(2).innertext)
'output.show(tds(3).innertext)
output.show("------")
End If
Next