首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用vba提取json格式的数据

使用vba提取json格式的数据
EN

Stack Overflow用户
提问于 2021-10-28 12:15:48
回答 1查看 41关注 0票数 0

我目前正在使用下面提到的代码从web中提取数据,代码是从web提取数据没有任何问题,现在我想提取相同的数据在json format.My代码是给定的below.My页面usrl下面的https://www.amazon.com/s?crid=AQO8JFH64H82&i=merchant-items&k=socks&me=A29M0OOY4LPNOT&qid=1635324852&ref=glow_cls&refresh=1&sprefix=socks%2Caps%2C315&low-price=0.1&high-price=5

代码语言:javascript
运行
复制
Set Ie = CreateObject("InternetExplorer.Application")
Ie.Visible = True
Ie.navigate "https://www.amazon.com/s?crid=AQO8JFH64H82&i=merchant-items&k=socks&me=A29M0OOY4LPNOT&qid=1635324852&ref=glow_cls&refresh=1&sprefix=socks%2Caps%2C315&low-price=0.1&high-price=5"
Set html = Ie.Document
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("C:\Data\test" & Format(Now(), "_yyyy-mm-dd_hh-mm") & ".txt", True, True)
If html1 Like "*a-section a-spacing-small a-spacing-top-small*" Then
If html1 Like "*a-pagination*" Then
pagen = html.getElementsByClassName("a-section a-spacing-small a-spacing-top-small")(0).innerText
pagen = Replace(pagen, "'", "")
endpage = html.getElementsByClassName("a-pagination")(0).innerText
fileout.write endpage
EN

回答 1

Stack Overflow用户

发布于 2021-10-28 13:48:44

首先,欢迎来到SO。

您必须决定是自己解析json,还是使用以下几个可用库中的一个:

要使用解析器的库,我建议首先转到Json

之后,请转到this answer;这是必须的,就这么简单:

代码语言:javascript
运行
复制
Dim p As Object
Set p = JSON.parse(strFormattedJSON)

但是,为了解析它,您需要了解内部结构,因为大多数JSON库将JSON对象解析为数组或字典,它们相互嵌套;也许您必须像这样访问它们:

代码语言:javascript
运行
复制
Debug.Print p.Item("a-pagination")(0)

解析你自己的

  1. here is a very good implementation。在to this one, the better.

中,This也很优秀

PS:我们的搜索引擎非常好;)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69753937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档