0

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

u'{ displayName:"iPhone 5 16GB 黑色",             
 productNameUrl:"apple-iphone-5-16gb-black-and-slate",                 
 _default:“true”,优先级:“1”,paymMinPrice:“9.99”,paymMinMrc:“46.00”,          
 paymMinContractLength:"24 个月",                    
 pagmMinPrice:"", paygMinMrc:"",                   
 paygMinContractLength:"",                    
 paymentTypeUrl:"pay-monthly" }           
 handset.imgURLimage_reg_url //handset.contactless
 非接触式手机。颜色颜色           
 手机比较 比较手机 独家 独家      
 手机.dmMessage dmMessage 手机.ctaButton ctaButton  
 ifhsetDispArr["iphone-5"] !空{handDispObj
 hsetDispArr["iphone-5"]               
 handDispObj.handsets.pushhandset } 其他 {               
 手机.pushhandset handDispObj
 {productDispPFUrl:"iphone-5-group",
 productPFUrl:"apple-iphone-5-16gb-black-and-slate",
 制造商名称:“Apple”,productDispName:“iPhone 5”,
 手机:手机} 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。

4

2 回答 2

2

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

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

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

全部只使用拆分功能

于 2013-07-24T07:48:08.997 回答
1
u_str = 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 colourshandset.compare compare handset.exclusive exclusivehandset.dmMessage dmMessage handset.ctaButton ctaButtonifhsetDispArr["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 {}'

str_to_find = 'productNameUrl'
p1 = u_str.find(str_to_find)+len(str_to_find)+1
p2 = u_str.find('",', u_str.find(str_to_find))+1
print u_str[p1:p2]
于 2013-07-24T07:45:59.833 回答