我目前正在使用下面提到的代码从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
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发布于 2021-10-28 13:48:44
首先,欢迎来到SO。
您必须决定是自己解析json,还是使用以下几个可用库中的一个:
要使用解析器的库,我建议首先转到Json
之后,请转到this answer;这是必须的,就这么简单:
Dim p As Object
Set p = JSON.parse(strFormattedJSON)但是,为了解析它,您需要了解内部结构,因为大多数JSON库将JSON对象解析为数组或字典,它们相互嵌套;也许您必须像这样访问它们:
Debug.Print p.Item("a-pagination")(0)解析你自己的
中,This也很优秀
PS:我们的搜索引擎非常好;)
https://stackoverflow.com/questions/69753937
复制相似问题