利用爬虫获取到京东商城销量最高的格子大衣的评论数,但是获取到的数据杂乱无章(见下),让人头大,下面就介绍一下如何利用json将这堆数据规整化。
fetchJSON_comment98({"jwotestProduct":null,"score":0,"comments":[{"id":14993742522,"guid":"5ce46f3a3737117b024d5d9e79c226b3","content":"衣服收到了,质量非常好,很喜欢,穿上很暖和还好看,大气上档次。快递小哥服务态度也很好,而且很快。非常开心的购物,关键是衣服真好看,喜欢的小伙伴下手吧!","creationTime":"2020-12-03 10:04:57","isDelete":false,"isTop":false,"userImageUrl":"storage.360buyimg.com/i.imageUpload/67756f79696e676a756e3230313531343236333837373039333333_sma.jpg","topped":0,"replies":[],"replyCount":1,"score":5,"imageStatus":1,"title":"","usefulVoteCount":0,"userClient":4,"discussionId":830847409,"imageCount":2,"anonymousFlag":1,"plusAvailable":201,"mobileVersion":"","images":[{"id":1301517166,"imgUrl":"//img30.360buyimg.com/n0/s128x96_jfs/t1/135249/34/18183/321775/5fc847c8E31b3a256/002663269aae2eaa.jpg","imgTitle":"","status":0},{"id":1301517167,"imgUrl":"//img30.360buyimg.com/n0/s128x96_jfs/t1/142467/9/16783/227608/5fc847c9E19b51588/b74ee1467c7145b1.jpg","imgTitle":"","status":0}],"videos":[{"id":1301517168,"mainUrl":"https://img.300hu.com/4c1f7a6atransbjngwcloud1oss/21cb0188386820039142019073/imageSampleSnapshot/1606961095_627368485.100_430.jpg","videoHeight":1280,"videoWidth":720,"videoLength":4,"videoTitle":"","videoUrl":520462203,"videoId":520462203,"status":0,"remark":"https://vod.300hu.com/4c1f7a6atransbjngwcloud1oss/21cb0188386820039142019073/v.f30.mp4?source=1&h265=v.f1022_h265.mp4"}],"mergeOrderStatus":2,"productColor":"绿色","productSize":"XL(130-145斤)","textIntegral":40,"imageIntegral":40,"status":1,"referenceId":"10020517258571","referenceTime":"2020-10-11 11:03:44","nickname":"领***6","replyCount2":1,"userImage":"storage.360buyimg.com/i.imageUpload/67756f79696e676a756e3230313531343236333837373039333333_sma.jpg","orderId":0,"integral":80,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":53,"afterDays":0},{"id":16472391334,"guid":"bc60e3b2c69edb89646e47c50d73eaf3","content":"款式很流行,上身效果很好,很合身,面料好款式喜欢。没有色差 穿着时尚。","creationTime":"2021-10-16 20:13:34","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":911143827,"commentId":16472391334,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"116.21.128.245","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-16 22:30:14","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-14 11:44:39","nickname":"****O","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16507196631,"guid":"5569a613b1d94c51b49e798640980f60","content":"面料挺好的,款式不错,上身效果非常棒,尺码很标准。颜色很喜欢,很满意的一次购物。","creationTime":"2021-10-23 18:04:51","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replyCount":0,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-21 15:58:09","nickname":"****O","replyCount2":0,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16501437813,"guid":"290736015566d77ad0c6d33a27518f75","content":"衣服到手啦,颜色很美,上身效果挺好。料子特别舒服。尺码大小合适,质量好,特别推进。","creationTime":"2021-10-22 17:09:58","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":917898915,"commentId":16501437813,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"113.109.207.196","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-23 16:55:36","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-20 16:12:40","nickname":"****c","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16452080804,"guid":"533ca638d4405c9594a941730fc18e89","content":"收到了,尺寸大小合适,没有异味,面料柔软舒适。做工很好。非常百搭,好评。","creationTime":"2021-10-12 18:47:39","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":907612744,"commentId":16452080804,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"113.109.204.27","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-12 20:32:27","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-10 17:16:25","nickname":"****K","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16497141791,"guid":"16b278aff4af1bdea305e1afd3fd7d6d","content":"衣服做工精细,款式时尚,面料很好,穿在身上特漂亮。大小也合适。","creationTime":"2021-10-21 20:03:15","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":916985040,"commentId":16497141791,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"113.109.207.196","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-22 09:57:53","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-19 16:18:54","nickname":"****n","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16168378164,"guid":"c98f67579ee6b7242bc48f44e279fcf8","content":"收到了,特别好看,上身效果很好,做工也不错,泌尿很舒适。做工很精细,很喜欢,很满意。”","vcontent":"收到了,特别好看,上身效果很好,做工也不错,泌尿很舒适。做工很精细,很喜欢,很满意。”","creationTime":"2021-08-20 17:00:00","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replyCount":0,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.0.2","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-08-18 12:08:19","nickname":"****F","replyCount2":0,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16476496338,"guid":"774719659545d5e58fbe1cac611edc8a","content":"质量很好,价格很实惠,做工精细,没有多余的线头。款式简单大方,穿着很舒适,质量蛮好的。建议购买。","creationTime":"2021-10-17 20:00:30","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":914135525,"commentId":16476496338,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"116.21.131.67","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-18 10:12:06","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-15 19:05:09","nickname":"载***塔","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16481842566,"guid":"ad4125b3bcb3dc96dcef6686799fa2cc","content":"收到了,款式漂亮,穿着很有气势,上身效果棒棒的。实物和图片描述一样,没有色差,物美价廉。","creationTime":"2021-10-18 19:12:04","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":914578931,"commentId":16481842566,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"116.21.131.67","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-18 20:02:34","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-16 21:51:36","nickname":"****y","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16344546496,"guid":"dec44ba9216f84818aa47f90eb0f5550","content":"版型新颖时尚,做工精细,没有多余的线头,卖家发货速度很快。推荐的尺码合适,满意。","vcontent":"版型新颖时尚,做工精细,没有多余的线头,卖家发货速度很快。推荐的尺码合适,满意。","creationTime":"2021-09-22 12:25:42","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":895534151,"commentId":16344546496,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"113.109.206.14","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-09-22 20:01:44","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.0.2","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-09-19 12:23:27","nickname":"****i","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":3,"afterDays":0}],"soType":5,"csv":"eid=100^^tagid=ALL^^pid=20003^^sku=14731504489^^sversion=1001^^pageSize=1","imageListCount":26,"hotCommentTagStatistics":[],"testId":"cmt","vTagStatistics":null,"maxPage":100,"productCommentSummary":{"skuId":10020517258568,"averageScore":5,"defaultGoodCount":0,"defaultGoodCountStr":"1000+","commentCount":0,"commentCountStr":"2000+","goodCount":0,"goodCountStr":"1800+","goodRate":0.98,"goodRateShow":98,"generalCount":0,"generalCountStr":"10+","generalRate":0.015,"generalRateShow":1,"poorCount":0,"poorCountStr":"10","poorRate":0.005,"poorRateShow":1,"videoCount":0,"videoCountStr":"1","afterCount":0,"afterCountStr":"10","showCount":0,"showCountStr":"10+","oneYear":0,"sensitiveBook":0,"fixCount":0,"plusCount":0,"plusCountStr":"0","buyerShow":0,"poorRateStyle":1,"generalRateStyle":2,"goodRateStyle":147,"installRate":0,"productId":10020517258568,"score1Count":10,"score2Count":3,"score3Count":9,"score4Count":6,"score5Count":1852},"productAttr":[{"unit":"厘米","name":"身高","type":"people_height","key":"firstAttribute"},{"unit":"公斤","name":"体重","type":"people_weight","key":"secondAttribute"}]});
json网址:JSON在线解析及格式化验证 - JSON.cn
将我们利用获取到的评论数据粘贴到这里,会提示格式错误,因为json要求以大括号开始,以大括号结束,我们直接获取到的数据很显然是不满足要求的。
手动安排大括号开始,大括号结束,数据变规整了:
但是如果只是手动处理,效率太慢,我们可以借助replace()函数进行数据处理,给出一个小例子,实现的是“love”替换“hello”
print('hello xiang'.replace('hello','love'))
# 输出
love xiang
利用replace()实现获取数据的规整化:
import requests
import json
# 必须以大括号开头,大括号结尾,借用replace修改数据
resp = requests.get('https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=10020517258568&score=0&sortType=5&page=0&pageSize=10&isShadowSku=0&fold=1')
content = resp.text
# 大括号开始
content = content.replace('fetchJSON_comment98(','')
# 大括号结束
new_content = content.replace(');','')
print(new_content)
规整化后的数据,大括号开头以及结尾:
{"jwotestProduct":null,"score":0,"comments":[{"id":14993742522,"guid":"5ce46f3a3737117b024d5d9e79c226b3","content":"衣服收到了,质量非常好,很喜欢,穿上很暖和还好看,大气上档次。快递小哥服务态度也很好,而且很快。非常开心的购物,关键是衣服真好看,喜欢的小伙伴下手吧!","creationTime":"2020-12-03 10:04:57","isDelete":false,"isTop":false,"userImageUrl":"storage.360buyimg.com/i.imageUpload/67756f79696e676a756e3230313531343236333837373039333333_sma.jpg","topped":0,"replies":[],"replyCount":1,"score":5,"imageStatus":1,"title":"","usefulVoteCount":0,"userClient":4,"discussionId":830847409,"imageCount":2,"anonymousFlag":1,"plusAvailable":201,"mobileVersion":"","images":[{"id":1301517166,"imgUrl":"//img30.360buyimg.com/n0/s128x96_jfs/t1/135249/34/18183/321775/5fc847c8E31b3a256/002663269aae2eaa.jpg","imgTitle":"","status":0},{"id":1301517167,"imgUrl":"//img30.360buyimg.com/n0/s128x96_jfs/t1/142467/9/16783/227608/5fc847c9E19b51588/b74ee1467c7145b1.jpg","imgTitle":"","status":0}],"videos":[{"id":1301517168,"mainUrl":"https://img.300hu.com/4c1f7a6atransbjngwcloud1oss/21cb0188386820039142019073/imageSampleSnapshot/1606961095_627368485.100_430.jpg","videoHeight":1280,"videoWidth":720,"videoLength":4,"videoTitle":"","videoUrl":520462203,"videoId":520462203,"status":0,"remark":"https://vod.300hu.com/4c1f7a6atransbjngwcloud1oss/21cb0188386820039142019073/v.f30.mp4?source=1&h265=v.f1022_h265.mp4"}],"mergeOrderStatus":2,"productColor":"绿色","productSize":"XL(130-145斤)","textIntegral":40,"imageIntegral":40,"status":1,"referenceId":"10020517258571","referenceTime":"2020-10-11 11:03:44","nickname":"领***6","replyCount2":1,"userImage":"storage.360buyimg.com/i.imageUpload/67756f79696e676a756e3230313531343236333837373039333333_sma.jpg","orderId":0,"integral":80,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":53,"afterDays":0},{"id":16472391334,"guid":"bc60e3b2c69edb89646e47c50d73eaf3","content":"款式很流行,上身效果很好,很合身,面料好款式喜欢。没有色差 穿着时尚。","creationTime":"2021-10-16 20:13:34","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":911143827,"commentId":16472391334,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"116.21.128.245","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-16 22:30:14","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-14 11:44:39","nickname":"****O","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16507196631,"guid":"5569a613b1d94c51b49e798640980f60","content":"面料挺好的,款式不错,上身效果非常棒,尺码很标准。颜色很喜欢,很满意的一次购物。","creationTime":"2021-10-23 18:04:51","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replyCount":0,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-21 15:58:09","nickname":"****O","replyCount2":0,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16501437813,"guid":"290736015566d77ad0c6d33a27518f75","content":"衣服到手啦,颜色很美,上身效果挺好。料子特别舒服。尺码大小合适,质量好,特别推进。","creationTime":"2021-10-22 17:09:58","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":917898915,"commentId":16501437813,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"113.109.207.196","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-23 16:55:36","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-20 16:12:40","nickname":"****c","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16452080804,"guid":"533ca638d4405c9594a941730fc18e89","content":"收到了,尺寸大小合适,没有异味,面料柔软舒适。做工很好。非常百搭,好评。","creationTime":"2021-10-12 18:47:39","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":907612744,"commentId":16452080804,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"113.109.204.27","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-12 20:32:27","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-10 17:16:25","nickname":"****K","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16497141791,"guid":"16b278aff4af1bdea305e1afd3fd7d6d","content":"衣服做工精细,款式时尚,面料很好,穿在身上特漂亮。大小也合适。","creationTime":"2021-10-21 20:03:15","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":916985040,"commentId":16497141791,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"113.109.207.196","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-22 09:57:53","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-19 16:18:54","nickname":"****n","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16168378164,"guid":"c98f67579ee6b7242bc48f44e279fcf8","content":"收到了,特别好看,上身效果很好,做工也不错,泌尿很舒适。做工很精细,很喜欢,很满意。”","vcontent":"收到了,特别好看,上身效果很好,做工也不错,泌尿很舒适。做工很精细,很喜欢,很满意。”","creationTime":"2021-08-20 17:00:00","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replyCount":0,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.0.2","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-08-18 12:08:19","nickname":"****F","replyCount2":0,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16476496338,"guid":"774719659545d5e58fbe1cac611edc8a","content":"质量很好,价格很实惠,做工精细,没有多余的线头。款式简单大方,穿着很舒适,质量蛮好的。建议购买。","creationTime":"2021-10-17 20:00:30","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":914135525,"commentId":16476496338,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"116.21.131.67","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-18 10:12:06","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-15 19:05:09","nickname":"载***塔","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16481842566,"guid":"ad4125b3bcb3dc96dcef6686799fa2cc","content":"收到了,款式漂亮,穿着很有气势,上身效果棒棒的。实物和图片描述一样,没有色差,物美价廉。","creationTime":"2021-10-18 19:12:04","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":914578931,"commentId":16481842566,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"116.21.131.67","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-10-18 20:02:34","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.3.4","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-10-16 21:51:36","nickname":"****y","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":2,"afterDays":0},{"id":16344546496,"guid":"dec44ba9216f84818aa47f90eb0f5550","content":"版型新颖时尚,做工精细,没有多余的线头,卖家发货速度很快。推荐的尺码合适,满意。","vcontent":"版型新颖时尚,做工精细,没有多余的线头,卖家发货速度很快。推荐的尺码合适,满意。","creationTime":"2021-09-22 12:25:42","isDelete":false,"isTop":false,"userImageUrl":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","topped":0,"replies":[{"id":895534151,"commentId":16344546496,"content":"您好,非常感谢您对本店的商品给出宝贵意见和评价,如您在收到商品之后发现有任何问题,可以随时联系我们在线客服,我们将竭诚为您服务,欢迎下次光临","pin":"颖***店","userClient":98,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","ip":"113.109.206.14","productId":10020517258573,"replyList":[],"nickname":"颖***店","creationTime":"2021-09-22 20:01:44","parentId":0,"targetId":0,"venderShopInfo":{"id":10251345,"appName":"//mall.jd.com/index-10251345.html","title":"颖墨旗舰店","venderId":10395710}}],"replyCount":1,"score":5,"title":"","usefulVoteCount":0,"userClient":2,"anonymousFlag":1,"plusAvailable":0,"mobileVersion":"9.0.2","productColor":"绿色","productSize":"请拍正确尺码","textIntegral":10,"status":1,"referenceId":"10020517258573","referenceTime":"2021-09-19 12:23:27","nickname":"****i","replyCount2":1,"userImage":"misc.360buyimg.com/user/myjd-2015/css/i/peisong.jpg","orderId":0,"integral":10,"productSales":"[]","referenceImage":"jfs/t1/140592/13/9390/232273/5f720223Ed1757424/ca5188b74b0d9374.jpg","referenceName":"颖墨毛呢大衣女时尚秋冬2021年新款宽松韩版格子中长款加厚毛呢大衣外套女潮 A66 绿色 S(85-100斤)","firstCategory":1315,"secondCategory":1343,"thirdCategory":9706,"aesPin":null,"days":3,"afterDays":0}],"soType":5,"csv":"eid=100^^tagid=ALL^^pid=20003^^sku=14731504489^^sversion=1001^^pageSize=1","imageListCount":26,"hotCommentTagStatistics":[],"testId":"cmt","vTagStatistics":null,"maxPage":100,"productCommentSummary":{"skuId":10020517258568,"averageScore":5,"defaultGoodCount":0,"defaultGoodCountStr":"1000+","commentCount":0,"commentCountStr":"2000+","goodCount":0,"goodCountStr":"1800+","goodRate":0.98,"goodRateShow":98,"generalCount":0,"generalCountStr":"10+","generalRate":0.015,"generalRateShow":1,"poorCount":0,"poorCountStr":"10","poorRate":0.005,"poorRateShow":1,"videoCount":0,"videoCountStr":"1","afterCount":0,"afterCountStr":"10","showCount":0,"showCountStr":"10+","oneYear":0,"sensitiveBook":0,"fixCount":0,"plusCount":0,"plusCountStr":"0","buyerShow":0,"poorRateStyle":1,"generalRateStyle":2,"goodRateStyle":147,"installRate":0,"productId":10020517258568,"score1Count":10,"score2Count":3,"score3Count":9,"score4Count":6,"score5Count":1852},"productAttr":[{"unit":"厘米","name":"身高","type":"people_height","key":"firstAttribute"},{"unit":"公斤","name":"体重","type":"people_weight","key":"secondAttribute"}]}
利用规整化后的数据获取买家的尺码以及衣服颜色:
import requests
import json
# 必须以大括号开头,大括号结尾,借用replace修改数据
resp = requests.get('https://club.jd.com/comment/productPageComments.action?callback=fetchJSON_comment98&productId=10020517258568&score=0&sortType=5&page=0&pageSize=10&isShadowSku=0&fold=1')
content = resp.text
# 实现大括号开头以及结尾,这里可以有多个空格,不影响
content = content.replace('fetchJSON_comment98(',' ')
new_content = content.replace(');',' ')
# print(new_content)
# 将替换后的数据传给josn工具,注意是loads而不是load
json_data = json.loads(new_content)
# 获取comments数据,comments是一个字典
comments = json_data['comments']
# 获取评论数目
sum = 0
# 获取键值对,comments字典里面存储的数据也是以字典形式存储
for item in comments:
sum += 1
# item 是一个字典,通过“键”获取“值”
color = item['productColor']
size = item['productSize']
print(color)
print(size)
print('评论数有'+str(sum)+'条')
我不太理解为什么comments里面是10个Object(利用其它URL得到的数据,comments里面也是10个Object):(一个json中有10个Object)