Foxtable(狐表)用户栏目专家坐堂 → 获取网页数据


  共有6332人关注过本帖树形打印复制链接

主题:获取网页数据

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/9/10 15:00:00 [显示全部帖子]

用下面代码慢慢获取。一次性获取会很慢,红色代码慢慢注释掉,理解代码。

 

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

 


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/1/3 23:12:00 [显示全部帖子]

以下是引用time在2016/1/1 9:58:00的发言:
请教楼主:获取的数据直接导入到表吗?内部表分别有哪些列表名是什么?上列代码是属于单击按钮事件吗?

 

不是,获取到的数据,只显示在命令窗口里。

 

你要看懂代码,然后把output.show改成增加行和赋值的代码即可。


 回到顶部