使用MSXML2.XMLHTTP从网页提取JSON值 [英] JSON values extraction from webpage using MSXML2.XMLHTTP

查看:1717
本文介绍了使用MSXML2.XMLHTTP从网页提取JSON值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我能够从网页中提取值,但面临问题json值提取.

Currently i am able to extract values from webpage but facing issue json value extraction.

我正在使用以下代码提取其他值.

I am using following code for other values extraction.

On Error Resume Next
Set http = CreateObject("MSXML2.XMLHTTP")
    http.Open "GET", url1234, False
    http.Send
    html.body.innerHTML = http.ResponseText
    brand = html.body.innerText
    'MsgBox (brand)

以上代码未提取该网址的以下值

Above code is not extracting following values of this url

"" : {"0":"B0037RYT96","1":"B0152VYOQ2","2":"B0152WOT70","3":"B003W0NYKS","4":"B0152WOT8Y","5":"B00C2O7M1M","6":"B0037RMS6W","7":"B0037RMI0S","8":"B0152VYPXY"},

推荐答案

在您的代码中没有任何试图提取此内容的内容.

There isn't anything I can see in your code that attempts to extract this.

您可以使用正则表达式指定适当的模式来提取该字符串.下面,您要搜索的字符串存储在r变量中.

You could use regex to specify the appropriate pattern to extract that string. Below, the string you are after is stored in r variable.

对所需的字符串进行编辑,可以将正则表达式更改为:

Given your edit to the required string you can change the regex to:

\"dimensionToAsinMap\" :(.*)[^\r\n].*

此处尝试

以前的答案:

尝试regex 此处

Option Explicit
Public Sub GetData()
    Dim s As String, r As String, re As Object
    Set re = CreateObject("vbscript.regexp")
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", "https://www.yoursite.com?tag=stackoverfl08-20", False
        .send
        s = .responseText
    End With
    With re
        .Global = True
        .MultiLine = True
        .IgnoreCase = False
        .Pattern = "(""dimensionToAsinMap"" :.(.|\n)*)[;^\r\n].*return dataToReturn"
        If .test(s) Then
            r = .Execute(s)(0).SubMatches(0)
        Else
            r = "No match"
        End If
    End With
End Sub


本地窗口检查:

正则表达式说明:

这篇关于使用MSXML2.XMLHTTP从网页提取JSON值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆