Excel精英培训网

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

vba 网抓后导入表格

[复制链接]
发表于 2019-11-6 14:36 | 显示全部楼层 |阅读模式
现在我想把下面代码里面的网抓内容填入表格中,类似附件表格那样的。
希望有高手能够帮忙看看



Sub test()
    Dim winhttp As Object
    Dim token As String
    Dim senddata As String
    Dim json As Object
    Set winhttp = CreateObject("winhttp.winhttprequest.5.1")
    With winhttp
        j = 0
        For i = 1 To 200
            .Open "GET", "http://www.lspipe.cn:8888/erp/login_now/?next=/", False
            .setrequestheader "Host", "www.lspipe.cn:8888"
            .send
            token = Split(Split(.getallresponseheaders, "Set-Cookie: csrftoken=")(1), ";")(0)
            senddata = "csrfmiddlewaretoken=" & token & "&username=%E6%B5%8F%E8%A7%88%E8%B4%A6%E5%8F%B7&password=123456"
            .Open "POST", "http://www.lspipe.cn:8888/erp/login_now/?next=/erp/index/", False
            .setrequestheader "Host", "www.lspipe.cn:8888"
            .setrequestheader "Content-Type", "application/x-www-form-urlencoded"
            .setrequestheader "Referer", "http://www.lspipe.cn:8888/erp/login_now/?next=/erp/index/"
            .send senddata
            .Open "POST", "http://www.lspipe.cn:8888/erp/inners/list/", False
            .setrequestheader "Host", "www.lspipe.cn:8888"
            .setrequestheader "Content-Type", "application/x-www-form-urlencoded"
            .setrequestheader "Referer", "http://www.lspipe.cn:8888/erp/page/inners/"
            .send "start=" & j & "&length=100"
            With CreateObject("msscriptcontrol.scriptcontrol")
                .Language = "jscript"
                .addcode "var mydata=" & winhttp.responsetext
                Set json = .codeobject.mydata.inners
            End With
            j = i * 100
        Next i
    End With
End Sub

表格样式.rar

10.34 KB, 下载次数: 5

表格样式

 楼主| 发表于 2019-11-7 17:51 | 显示全部楼层
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-19 16:05 , Processed in 0.311743 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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