如果用python正则把这个内容提取出来。
我想把下面的attrName和attrValue的值提取出来,写了好几种模式一直匹配不出来,请问要怎么写呢?
谢谢
[{"attrName":"Place of Origin","attrNameId":1,"attrValue":"China"},{"attrName":"Brand Name","attrNameId":2,"attrValue":"ZHONGKAI"},{"attrName":"Model Number","attrNameId":3,"attrValue":"45CC"},{"attrName":"Industrial Use","attrNameId":19421,"attrValue":"gift packaging","attrValueId":394282130},{"attrName":"Use","attrNameId":19427,"attrValue":"gift packaging","attrValueId":394282130},{"attrName":"Paper Type","attrNameId":19445,"attrValue":"cardboard","attrValueId":4},{"attrName":"Printing Handling","attrNameId":100003805,"attrValue":"Matt Lamination","attrValueId":1875805820},{"attrName":"Custom Order","attrNameId":100005412,"attrValue":"Accept","attrValueId":6722354},{"attrName":"Feature","attrNameId":191284141,"attrValue":"Disposable","attrValueId":76328288},{"attrName":"Shape","attrNameId":230093740,"attrValue":"square, square"},{"attrName":"Product name","attrValue":"Luxury Black Marble Jewelry Gift Box With Silver Foiling Logo"},{"attrName":"Usage","attrValue":"Jewelry Packaging"},{"attrName":"Size","attrValue":"Follow Customer's Requirement"},{"attrName":"Delivery time","attrValue":"About 8 workdays,based on QTY"},{"attrName":"Logo","attrValue":"Customer's Logo"},{"attrName":"Printing","attrValue":"CMYK or Pantone"},{"attrName":"Color","attrValue":"Black, Accept Customized"},{"attrName":"Shipping way","attrValue":"Express, sea transportation, air transport.etc"},{"attrName":"OEM/ODM","attrValue":"Avaliable"}],"productCategoryId":201268096,"productEncryptId":"IDX1x7H_-HW7-UJbBw-xc7vERtCg_xN1GTlExetkleQFEv-yvG333gL-3KRsKLDkssa3","productId":62437805348,"productIsCertified":false,"productIsExhibition":false,"productIsHang":false,"productIsMarketGoods":false,"productIsPersonal":false,"productLightCustomizationList":[{"customType":"Customized logo","moq":500},{"customType":"Customized packaging","moq":500},{"customType":"Graphic customization","moq":500},{"customType":"Custom Material","moq":500},{"customType":"Custom Size","moq":500}],"sample":{"priceUnit":"Piece","productSamplingOrderQuantity":2,"productSamplingType":"orderSample"},"sku":{"skuAttrs":[{"id":200001176,"name":"Color","values":[{"color":"#000000","fileName":"","id":3327837,"name":"Black","selected":true,"type":"COLOR","usable":true}]},{"id":200009677,"name":"Size","values":[{"color":"","fileName":"","id":-1,"name":"no","selected":true,"type":"TEXT","usable":true}]},{"id":208996422,"name":"Thickness","values":[{"color":"","fileName":"","id":-2,"name":"no","selected":true,"type":"TEXT","usable":true}]}],"skuInfoMap":{"200001176:3327837;200009677:-1;208996422:-2;":{"id":100611879599}},
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
"AttrName":".*?"
.*?
非贪婪匹配,确保能匹配出双引号里的内容,你可以加个括号来提取匹配组"AttrName":"(.*?)"
,方便在 python 里用 re.findall 提取出来。一定要用正则表达式吗?
感觉上是你的数据不完整,本来应该是比较好的json的,用json解析会方便很多的。