give me the vbs code for: [1. http get the response from the url:…
- User
give me the vbs code for: [1. http get the response from the url: https://papi.lenovo.com.cn/stock/getStockInfo.jhtm?ss=694&callback=jQueryJSONP_stock_getStockInfo&proInfos=%5B%7BactivityType%3A0%2C%20productCode%3A1039473%7D%5D&_=1750685229297 2. the response is structured like "jQueryJSONP_stock_getStockInfo([{ "productCode": "1039473", "salesNumber": "0", "serviceAgencyCode": "-999", "serviceAgencyNumber": "0", "activityType": "0", "message": "success", "needCheckSa": false }])" 3. help me get two outputs: a) productCode in integer and b) salesNumber in integer]
- Assistant
Below is a stand-alone VBScript (save it as e.g.
check_stock.vbs).
It- Performs a synchronous HTTP GET to the Lenovo URL.
- Strips the JSONP wrapper (
jQueryJSONP_stock_getStockInfo(...)). - Uses two regular expressions to grab
productCodeandsalesNumber. - Converts both to integers (type
Long) and prints them.
' check_stock.vbs Option Explicit Const URL = "https://papi.lenovo.com.cn/stock/getStockInfo.jhtm?ss=694&callback=jQueryJSONP_stock_getStockInfo&proInfos=%5B%7BactivityType%3A0%2C%20productCode%3A1039473%7D%5D&_=1750685229297" Dim http, respText Set http = CreateObject("MSXML2.XMLHTTP") http.Open "GET", URL, False ' False ⇒ synchronous http.Send If http.Status <> 200 Then WScript.Echo "HTTP error: " & http.Status WScript.Quit 1 End If respText = http.responseText ' Raw JSONP string ' ────────────────────────────────────────────────────────────── ' 1) OPTIONAL: quick sanity-check 'WScript.Echo respText ' ────────────────────────────────────────────────────────────── ' ------------------------------------------------------------- ' 2) Strip the JSONP wrapper: keep the text between the first ' parenthesis "(" and the last ")". ' ------------------------------------------------------------- Dim startPos, endPos, json startPos = InStr(respText, "(") + 1 endPos = InStrRev(respText, ")") - 1 json = Mid(respText, startPos, endPos - startPos + 1) ' Now "json" should contain something like: ' [ { "productCode": "1039473", "salesNumber": "0", ... } ] ' ------------------------------------------------------------- ' 3) Extract productCode and salesNumber with RegExp ' ------------------------------------------------------------- Dim regEx, matches, productCode, salesNumber Set regEx = New RegExp regEx.IgnoreCase = True regEx.Global = False ' --- productCode --- regEx.Pattern = """productCode""\s*:\s*""(\d+)""" Set matches = regEx.Execute(json) If matches.Count = 1 Then productCode = CLng(matches(0).SubMatches(0)) ' to Integer/Long Else WScript.Echo "productCode not found." WScript.Quit 1 End If ' --- salesNumber --- regEx.Pattern = """salesNumber""\s*:\s*""(\d+)""" Set matches = regEx.Execute(json) If matches.Count = 1 Then salesNumber = CLng(matches(0).SubMatches(0)) ' to Integer/Long Else WScript.Echo "salesNumber not found." WScript.Quit 1 End If ' ------------------------------------------------------------- ' 4) Output ' ------------------------------------------------------------- WScript.Echo "productCode (integer): " & productCode WScript.Echo "salesNumber (integer): " & salesNumberHow to run:
cscript //nologo check_stock.vbsSample output (based on your sample payload):
productCode (integer): 1039473 salesNumber (integer): 0That’s it—pure VBScript, no external JSON libraries needed; perfect for quick Windows automation.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.