Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 1091|回复: 1

VB抓取网上的数据~~大神请赐教!!紧急~~~

[复制链接]
发表于 2016-8-6 12:07 | 显示全部楼层 |阅读模式
我要抓取这个网页http:(增加双//)fz.people.com.cn/skygb/sk/index.php/Index/seach?&p=1
的数据,请问该如何修改下面的代码? ~~~紧急请大神赐教~~~


Option Explicit
Sub test()
    Dim HTML, tb, i&, j&, x&, n&, s$
    [a2:d9999] = ""
    Set HTML = CreateObject("htmlfile")
    With CreateObject("msxml2.xmlhttp")
        For x = 0 To 63
            .Open "get", "http:(增加双//)fz.people.com.cn/skygb/sk/index.php/Index/seach?&p=1
& 20 * x, False
            .Send
            Application.Wait (Now + TimeValue("00:00:02"))
            HTML.body.innerhtml = .responsetext
            Set tb = HTML.ALL.tags("table")(0).Rows
            For i = 1 To tb.Length - 1
                n = n + 1
                For j = 0 To tb(i).Cells.Length - 1
                    Cells(n + 1, j + 1) = tb(i).Cells(j).innertext
                Next
            Next
        Next
    End With
    MsgBox "??è?íê±?!"
End Sub

    MsgBox "获取完毕!"
End Sub

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
 楼主| 发表于 2016-8-6 12:08 | 显示全部楼层
我要抓取这个网页http:(增加双//)fz.people.com.cn/skygb/sk/index.php/Index/seach?&p=1
的数据,请问该如何修改下面的代码? ~~~紧急请大神赐教~~~


Option Explicit
Sub test()
    Dim HTML, tb, i&, j&, x&, n&, s$
    [a2:d9999] = ""
    Set HTML = CreateObject("htmlfile")
    With CreateObject("msxml2.xmlhttp")
        For x = 0 To 63
            .Open "get", "http:(增加双//)fz.people.com.cn/skygb/sk/index.php/Index/seach?&p=1
& 20 * x, False
            .Send
            Application.Wait (Now + TimeValue("00:00:02"))
            HTML.body.innerhtml = .responsetext
            Set tb = HTML.ALL.tags("table")(0).Rows
            For i = 1 To tb.Length - 1
                n = n + 1
                For j = 0 To tb(i).Cells.Length - 1
                    Cells(n + 1, j + 1) = tb(i).Cells(j).innertext
                Next
            Next
        Next
    End With
    MsgBox "??è?íê±?!"
End Sub

    MsgBox "获取完毕!"
End Sub

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-3 11:38 , Processed in 0.296909 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表