今天抓取数据的时候先使用re将想要的字典数据提取出来,然后使用json.loads再转化成dict类型的数据,再使用jsonpath提取数据。于是在使用re将数据提取出来以后,使用json.loads()将str类型的数据转换成dict类型的数据,但是 却报错了,报错显示json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 10 (char 9),使用正则提取出来的数据如下:
data = """
{ startTime : +new Date, ver : '8.0.39', st : '', online : true, shopVer : 2, appId : 1 , itemId : '630508807340', shopId : '35395691', shopName : 'BDCT brand', sellerId : '65386645', sellerNick : 'shixiawei0730', sibUrl : '//detailskip.taobao.com/service/getData/1/p1/item/detail/sib.htm?itemId=630508807340&sellerId=65386645&modules=dynStock,qrcode,viewer,price,duty,xmpPromotion,delivery,upp,activity,fqg,zjys,couponActivity,soldQuantity,page,originalPrice,tradeContract', descUrl : location.protocol==='http:' ? '//itemcdn.tmall.com/desc/icoss!0630508807340!11418747697?var=desc' : '//itemcdn.tmall.com/desc/icoss!0630508807340!11418747697?var=desc', counterApi : '//count.taobao.com/counter3?inc=ICVT_7_630508807340&sign=264646dc24ce97187fbc459b42ec96d6aac7a&keys=DFX_200_1_630508807340,ICVT_7_630508807340,ICCP_1_630508807340,SCCP_2_35395691', rateCounterApi : '//rate.taobao.com/detailCount.do?itemId=630508807340', areaPrice : false, lazyload : '#J_DivItemDesc', tadComponetCdn : true, delayInsurance : false, fuwubao : false, cdn : true, sibFirst : true, webp : true, descWebP : false, newDomain : true, asyncStock : true, enable : true, m_ratio : 20, beacon : {}, DyBase : { iurl : '//item.taobao.com', purl : '//paimai.taobao.com', durl : '//siteadmin.taobao.com', lgurl: 'https://login.taobao.com/member/login.jhtml', surl : '//upload.taobao.com', suitUrl: '//jubao.taobao.com/index.htm?&spm=a1z6q.7847058&itemId=' }, idata : { item: { id : '630508807340', title : 'BDCT\u539F\u521B\u65E5\u7CFB\u51AC\u5B63\u65B0\u6B3E\u52A0\u539A\u767D\u9E2D\u7ED2\u7ACB\u9886\u7FBD\u7ED2\u670D\u7537\u56FD\u6F6E\u4FDD\u6696\u9762\u5305\u670D\u5939\u514B', pic : '//gd3.alicdn.com/imgextra/i2/0/O1CN01wOEoiZ1yxSemAa9XA_!!0-item_pic.jpg', price : '', status : 0, descVersion : '', sellerNick : 'shixiawei0730', sellerNickGBK : 'shixiawei0730', skuComponentFirst: 'true', rcid : '30', cid : '50011167', virtQuantity : '', holdQuantity : '', quickAdd : 1, edit : true, initSizeJs:true, sizeGroupName:"中国号型A", auto: '', bnow : true, chong: false, dbst : 1644989802000, stepdata : { }, xjcc: false, type : 'ifashion', customHeader : false, disableAddToCart : !true, auctionImages : ["https://img.alicdn.com/bao/uploaded/i1/65386645/O1CN01dfAXnG1yxSeiJsERz_!!65386645.jpg","https://img.alicdn.com/bao/uploaded/i1/65386645/O1CN019UQz9Q1yxSci9Y2xL_!!65386645.png","https://img.alicdn.com/imgextra/i3/65386645/O1CN01Xa5dqQ1yxSUjirF1M_!!65386645.png","https://img.alicdn.com/imgextra/i3/65386645/O1CN01jgbptu1yxSZwIVgtn_!!65386645.jpg","https://img.alicdn.com/imgextra/i4/65386645/O1CN01Jjgzee1yxSaBLCCPo_!!65386645.jpg"] }, seller: { id : '65386645', mode : 0, shopAge : '14' ,status : 0 ,goldSeller : true }, shop : { id : '35395691', url : '//bdct.taobao.com/' ,pid: 1403302745 ,sid: 4 ,xshop: true ,instId: 382199999 } }, vdata :{ } }; g_config.tadInfo = {"tad_head_area":[{"name":"满就送","type":7}],"tad_second_area":[{"name":"掌柜推荐","type":4}],"tad_first_area":[{"name":"掌柜推荐","type":4}]};
"""
data = json.loads(data)
打印看了一下数据类型是str类型的,但是就是转化不了dict类型的数据,回到数据一看发现问题所在,这个str类型的数据乍一看上去有引号和冒号,不仔细看的话就以为是json类型的数据,这样发现问题所在了,所以在后面的数据提取中使用re提取数据就没有问题了