EXCEL VBA抓取网页JSON数据并解析

EXCEL VBA抓取网页JSON数据并解析

链接地址:

https://api.api68.com/CQShiCai/getBaseCQShiCaiList.do?lotCode=10036\&date=2024-01-26

python 复制代码
Sub test()
On Error Resume Next
Sheet.Select
Sheet1.Cells.ClearContents
[a1:g1] = Split("preDrawIssue|preDrawTime|preDrawCode 1|preDrawCode 2|preDrawCode 3|preDrawCode 4|preDrawCode 5", "|")
    Dim t As Object


    Set t = CreateObject("ScriptControl")
    t.Language = "JScript"

    sj = Format(Now, "yyyy-mm-dd")
   
  
    Dim xmlhttp As Object
  
    Set xmlhttp = CreateObject("winhttp.winhttprequest.5.1")
    With xmlhttp
    
    .Open "GET", "https://api.api68.com/CQShiCai/getBaseCQShiCaiList.do?lotCode=10036&date=" & sj, False
    .SetRequestHeader "Host", "api.api68.com"
    .SetRequestHeader "Connection", "keep-alive"
    
   
    .SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3947.100 Safari/537.36"
                                 
    .Send
    strtext = .responseText
  
        Set y = t.eval("eval(" & strtext & ")")
    End With
  
  For i = 0 To 5000
   If CallByName(CallByName(CallByName(CallByName(y, "result", VbGet), "data", VbGet), i, VbGet), "preDrawIssue", VbGet) = Empty Then Exit Sub
  Cells(2 + i, 1) = CallByName(CallByName(CallByName(CallByName(y, "result", VbGet), "data", VbGet), i, VbGet), "preDrawIssue", VbGet)
  Cells(2 + i, 2) = CallByName(CallByName(CallByName(CallByName(y, "result", VbGet), "data", VbGet), i, VbGet), "preDrawTime", VbGet)
  arr = Split(CallByName(CallByName(CallByName(CallByName(y, "result", VbGet), "data", VbGet), i, VbGet), "preDrawCode", VbGet), ",")
   Cells(2 + i, 3) = arr(0)
 Cells(2 + i, 4) = arr(1)
Cells(2 + i, 5) = arr(2)
Cells(2 + i, 6) = arr(3)
Cells(2 + i, 7) = arr(4)
  DoEvents
 

Next
End Sub
相关推荐
Stay Passion3 小时前
Java实用注解篇: @JSONField
java·开发语言·json
杜子腾dd14 小时前
12.Excel:查找替换
excel
南郁15 小时前
005-nlohmann/json 基础方法-C++开源库108杰
c++·开源·json
CodeJourney.15 小时前
基于DeepSeek与HTML的可视化图表创新研究
数据库·人工智能·信息可视化·excel
别催小唐敲代码17 小时前
解决跨域的4种方法
java·服务器·前端·json
橙色小博19 小时前
Python中的JSON库,详细介绍与代码示例
数据库·python·json
龙虎榜小红牛系统19 小时前
Python项目源码57:数据格式转换工具1.0(csv+json+excel+sqlite3)
python·json·excel
wtsolutions1 天前
在Excel中轻松处理嵌套JSON数据:json-to-excel插件使用指南
json·excel·nested·嵌套·json-to-excel
課代表1 天前
Excel VBA 自定义函数
excel·vba·自定义函数
vortex51 天前
深入理解 Bash 中的 $‘...‘ 字符串语法糖
开发语言·bash·excel