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
相关推荐
CodeCraft Studio5 小时前
Excel处理控件Aspose.Cells教程:使用 Python 将 Pandas DataFrame 转换为 Excel
python·json·excel·pandas·csv·aspose·dataframe
星空的资源小屋9 小时前
PPTist,一个完全免费的 AI 生成 PPT 在线网站
人工智能·python·电脑·excel
开开心心_Every9 小时前
免费语音合成工具:66种音色随心选
人工智能·面试·java-ee·计算机外设·电脑·maven·excel
敬业小码哥1 天前
记一次:mysql的json及json数组使用组合使用
数据库·mysql·json
一键三联啊1 天前
BSON 和 JSON 的区别
json
偷心伊普西隆1 天前
EXCEL VBA 清空Excel工作表(Sheet)的方法
microsoft·excel
Coding_Doggy1 天前
苍穹外卖Day12 | Apache POI、导出Excel报表、HttpServletResponse、工作台
excel
l1t2 天前
张泽鹏先生手搓的纯ANSI处理UTF-8与美团龙猫调用expat库读取Excel xml对比测试
xml·人工智能·excel·utf8·expat
一个很老的小萌新2 天前
json 解析 [{“id“:1,“name“:“apple“},{“id“:2,“name“:“banana“}]
java·前端·json
Source.Liu2 天前
【Python自动化】 21 Pandas Excel 操作完整指南
python·excel·pandas