gpt4 book ai didi

javascript - 如何从脚本中提取数据?

转载 作者:行者123 更新时间:2023-11-28 20:23:34 25 4
gpt4 key购买 nike

这是包含所需数据的脚本在 html 页面上的样子:

 u'{                    displayName:"iPhone 5 16GB Black",              productNameUrl:"apple-iphone-5-16gb-black-and-slate",                  _default:"true",                     priority:"1",                     paymMinPrice:"9.99",                     paymMinMrc:"46.00",           paymMinContractLength:"24 Months",                     pagmMinPrice:"",                     paygMinMrc:"",                    paygMinContractLength:"",                     paymentTypeUrl:"pay-monthly"                }            handset.imgURLimage_reg_url            //handset.contactless  contactless            handset.colours  colours            handset.compare  compare            handset.exclusive  exclusive       handset.dmMessage  dmMessage            handset.ctaButton  ctaButton   ifhsetDispArr["iphone-5"] ! null {                handDispObj  hsetDispArr["iphone-5"]                handDispObj.handsets.pushhandset            } else {                handsets.pushhandset                handDispObj  {productDispPFUrl:"iphone-5-group", productPFUrl:"apple-iphone-5-16gb-black-and-slate", manufacturerName:"Apple", productDispName:"iPhone 5", handsets:handsets}                hsetDispKeys.push"iphone-5"          }            handDispObj.handsets.sortfunctionh1,h2{ifh1._default  "true"{return false}else ifh2._default  "true"{return true}else{return h1.priority > h2.priority}}            hsetDispArr["iphone-5"]  handDispObj                   var handDispObj  {}'

我需要从此脚本中提取 productNameUrl (从顶部开始的第二个标签)标签下的信息。有人可以告诉我该怎么做吗?

由于此脚本不是标准 JSON 格式,因此我也无法使用 JSON.loads。

最佳答案

假设您的信息字符串存储在“info”中

var productNameUrl = info.split('productNameUrl:"')[1];

ProductNameUrl = productNameUrl.split('"')[0];

全部只使用split功能

关于javascript - 如何从脚本中提取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17827675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com