在购买商品的时候,这个商品质量怎么样、价格贵不贵、商家服务态度好不好?这些问题往往是购买者急需知道的信息。
京东平台提供了商品评价功能,能够让购买者通过其他购买者的反馈来决定自己到底买不买这个商品。
项目组在对“杀京东”程序进行需求调研时,认为提供商品的评价尤其是差评信息,对购买者非常有指导意义,能加强用户的操作体验。此时,如何获取京东商品的评价信息成为项目组的首要任务。
首先还是先上神器Fiddler,通过它来获取到访问地址。
//差评 http://club.jd.com/productpage/p-255742-s-1-t-3-p-0.html?callback=fetchJSON_comment98vv17736 //中评 http://club.jd.com/productpage/p-255742-s-2-t-3-p-0.html?callback=fetchJSON_comment98vv17736 //好评 http://club.jd.com/productpage/p-255742-s-3-t-3-p-0.html?callback=fetchJSON_comment98vv17736
获取评价信息的网址解析如下:
最重要的数据是:p-255742-s-1-t-3-p-0.html,解析如下:p应该是Product的意思,255742是商品skuid,s是索引,1表示差评、2表示中评、3表示好评,最后的0表示第一页,若使用1、2、3等代替,可分别打开不同页的评价信息。
从网页上可以看出,京东的评价信息以10个评价作为分页标准。
回馈的Json数据样例如下,有点长哈。
{ "productAttr" : null, "productCommentSummary" : { "beginRowNumber" : 0, "endRowNumber" : 0, "skuId" : 974811, "productId" : 974811, "score1Count" : 145, "score2Count" : 75, "score3Count" : 252, "score4Count" : 1183, "score5Count" : 17106, "showCount" : 2069, "commentCount" : 18761, "averageScore" : 5, "goodCount" : 18289, "goodRate" : 0.976, "goodRateShow" : 97, "goodRateStyle" : 146, "generalCount" : 327, "generalRate" : 0.017, "generalRateShow" : 2, "generalRateStyle" : 3, "poorCount" : 145, "poorRate" : 0.0070, "poorRateShow" : 1, "poorRateStyle" : 1 }, "hotCommentTagStatistics" : [{ "id" : 119397, "name" : "做工精美", "status" : 0, "rid" : 16809, "productId" : 974811, "count" : 210, "created" : "2013-10-30 00:47:57", "modified" : "2016-03-27 09:55:22" }, { "id" : 119775, "name" : "大小适合", "status" : 0, "rid" : 16811, "productId" : 974811, "count" : 79, "created" : "2013-10-30 11:13:00", "modified" : "2016-03-24 08:01:25" }, { "id" : 122181, "name" : "物美价廉", "status" : 0, "rid" : 16813, "productId" : 974811, "count" : 66, "created" : "2013-11-01 16:38:55", "modified" : "2016-03-27 22:47:09" } ], "jwotestProduct" : "98", "score" : 1, "soType" : 3, "imageListCount" : 500, "comments" : [{ "id" : 1420471635, "guid" : "7b1a240b-eb7b-4e47-b803-40133e8b2165", "content" : "松木容易开裂,发货前没有检查,边条都裂了,目前不影响使用,客服说自己拿胶布缠一下,不知道是不是因为特价购买才有瑕疵的", "creationTime" : "2016-03-27 22:22:18", "isTop" : false, "referenceId" : "973878", "referenceImage" : "g15/M04/0B/1F/rBEhWVJBc_IIAAAAAAEbkVP9b9kAADeWwNLNWQAARup896.jpg", "referenceName" : "得力(deli)33055 可升降双面磁性多功能木制儿童画板/画架/学生白板/粉笔绿板", "referenceTime" : "2016-03-03 08:21:43", "referenceType" : "Product", "referenceTypeId" : 0, "firstCategory" : 670, "secondCategory" : 729, "thirdCategory" : 1449, "replyCount" : 0, "score" : 1, "status" : 1, "title" : "", "usefulVoteCount" : 0, "uselessVoteCount" : 0, "userImage" : "storage.jd.com/i.imageUpload/79696368656e673230323631343537303832313038303733_sma.jpg", "userImageUrl" : "storage.jd.com/i.imageUpload/79696368656e673230323631343537303832313038303733_sma.jpg", "userLevelId" : "62", "userProvince" : "福建", "userRegisterTime" : "2009-12-16 14:33:04", "viewCount" : 0, "orderId" : 0, "isReplyGrade" : false, "nickname" : "y***6", "userClient" : 2, "productColor" : "", "productSize" : "升降范围:77~132cm原木色", "integral" : -20, "anonymousFlag" : 1, "userLevelName" : "金牌会员", "recommend" : false, "userLevelColor" : "#088000", "userClientShow" : "<a href='http://app.jd.com/iphone.html' target='_blank'>来自京东iPhone客户端</a>", "isMobile" : true, "days" : 24 }, { "id" : 1409721181, "guid" : "29691394-5cdf-4309-860d-204e3dc24051", "content" : "超级差,四个支柱长短不一致,画板立起来后不稳,摇晃的根本就不能用。买的时候就是考虑到品牌的东西,质量应该有保障,谁知道还不如杂牌子的便宜货!垃圾东西!", "creationTime" : "2016-03-22 23:08:53", "isTop" : false, "referenceId" : "1546185", "referenceImage" : "g15/M04/0B/1F/rBEhWVJBc_IIAAAAAAEbkVP9b9kAADeWwNLNWQAARup896.jpg", "referenceName" : "得力(deli)33055 可升降双面磁性多功能木制儿童画板/画架/学生白板/粉笔绿板", "referenceTime" : "2016-03-20 18:27:26", "referenceType" : "Product", "referenceTypeId" : 0, "firstCategory" : 670, "secondCategory" : 729, "thirdCategory" : 1449, "replyCount" : 0, "score" : 1, "status" : 1, "usefulVoteCount" : 0, "uselessVoteCount" : 0, "userImage" : "misc.360buyimg.com/lib/img/u/b62.gif", "userImageUrl" : "misc.360buyimg.com/lib/img/u/b62.gif", "userLevelId" : "62", "userProvince" : "", "userRegisterTime" : "2014-07-10 23:29:15", "viewCount" : 0, "orderId" : 0, "isReplyGrade" : false, "nickname" : "h***B", "userClient" : 21, "mergeOrderStatus" : -2, "discussionId" : 80351696, "productColor" : "", "productSize" : "可升降可旋转 粉色", "integral" : -20, "anonymousFlag" : 1, "userLevelName" : "金牌会员", "recommend" : false, "userLevelColor" : "#088000", "userClientShow" : "<a href='javascript:;'>来自微信购物</a>", "isMobile" : false, "days" : 2 }, { "id" : 1404857619, "guid" : "6c31d7f1-654f-47e7-9dff-f6b356d0f73e", "content" : "垃圾画板,送来上面就有胶印,弄半天都擦不掉,什么破玩意啊……后悔死啦,", "creationTime" : "2016-03-20 22:54:57", "isTop" : false, "referenceId" : "974811", "referenceImage" : "g15/M04/0B/1F/rBEhWVJBc_IIAAAAAAEbkVP9b9kAADeWwNLNWQAARup896.jpg", "referenceName" : "得力(deli)33055 可升降双面磁性多功能木制儿童画板/画架/学生白板/粉笔绿板", "referenceTime" : "2016-03-08 12:41:08", "referenceType" : "Product", "referenceTypeId" : 0, "firstCategory" : 670, "secondCategory" : 729, "thirdCategory" : 1449, "replyCount" : 0, "score" : 1, "status" : 1, "usefulVoteCount" : 0, "uselessVoteCount" : 0, "userImage" : "storage.360buyimg.com/i.imageUpload/6a645f3431323935663939633835326431343439333938383136343831_sma.jpg", "userImageUrl" : "storage.360buyimg.com/i.imageUpload/6a645f3431323935663939633835326431343439333938383136343831_sma.jpg", "userLevelId" : "61", "userProvince" : "", "userRegisterTime" : "2015-12-06 15:19:32", "viewCount" : 0, "orderId" : 0, "isReplyGrade" : false, "nickname" : "j***d", "userClient" : 4, "images" : [{ "id" : 131794347, "associateId" : 79914966, "productId" : 0, "imgUrl" : "//img30.360buyimg.com/shaidan/s128x96_jfs/t2317/290/2689843034/63000/3b7a38a4/56eeb9c0N39f520c4.jpg", "available" : 1, "pin" : "", "dealt" : 0, "imgTitle" : "", "isMain" : 0 }, { "id" : 131794348, "associateId" : 79914966, "productId" : 0, "imgUrl" : "//img30.360buyimg.com/shaidan/s128x96_jfs/t2026/247/2815215176/40430/51aaae4e/56eeb9c1Nb2277503.jpg", "available" : 1, "pin" : "", "dealt" : 0, "imgTitle" : "", "isMain" : 0 } ], "showOrderComment" : { "id" : 79914966, "guid" : "ce5c627c-200f-4976-ba17-ccc805e7fcf3", "content" : "垃圾画板,送来上面就有胶印,弄半天都擦不掉,什么破玩意啊……后悔死啦,<div class='uploadimgdiv'><img class='uploadimg' border='0' src='http://img30.360buyimg.com/shaidan/jfs/t2317/290/2689843034/63000/3b7a38a4/56eeb9c0N39f520c4.jpg' /></div><div class='uploadimgdiv'><img class='uploadimg' border='0' src='http://img30.360buyimg.com/shaidan/jfs/t2026/247/2815215176/40430/51aaae4e/56eeb9c1Nb2277503.jpg' /></div>", "creationTime" : "2016-03-20 22:54:57", "isTop" : false, "referenceId" : "974811", "referenceType" : "Order", "referenceTypeId" : 0, "firstCategory" : 0, "secondCategory" : 0, "thirdCategory" : 0, "replyCount" : 0, "score" : 0, "status" : 1, "usefulVoteCount" : 0, "uselessVoteCount" : 0, "userProvince" : "", "viewCount" : 0, "orderId" : 0, "isReplyGrade" : false, "userClient" : 4, "isDeal" : 1, "integral" : -10, "anonymousFlag" : 1, "recommend" : false, "userLevelColor" : "#999999", "userClientShow" : "<a href='http://app.jd.com/android.html' target='_blank'>来自京东Android客户端</a>", "isMobile" : true }, "mergeOrderStatus" : 2, "discussionId" : 79914966, "productColor" : "", "productSize" : "升降范围:57~96.5cm原木色", "imageCount" : 2, "integral" : -10, "anonymousFlag" : 1, "userLevelName" : "银牌会员", "recommend" : false, "userClientShow" : "<a href='http://app.jd.com/android.html' target='_blank'>来自京东Android客户端</a>", "isMobile" : true, "days" : 12 } ], "topFiveCommentVos" : [] }
从上面的Json可以看出,其中productCommentSummary与comments中数据比较重要。在productCommentSummary中差评数量,根据差评数量,可以计算出差评有几页,然后就可以取到所有的差评数据了。
/// <summary> /// 评价数据模型 /// </summary> public class EvaluateMsg { /// <summary> /// 产品属性 /// </summary> public object productAttr { get; set; } /// <summary> /// 评价属性 /// </summary> public MsgSummary productCommentSummary { get; set; } /// <summary> /// 评价标签 /// </summary> public object hotCommentTagStatistics { get; set; } public string jwotestProduct { get; set; } public int score { get; set; } public int soType { get; set; } public int imageListCount { get; set; } private List<BadpostMsg> _msgs = new List<BadpostMsg>(); /// <summary> /// 评价信息 /// </summary> public List<BadpostMsg> comments { get { return _msgs; } set { _msgs = value; } } public object topFiveCommentVos { get; set; } }
完整的获取评价信息代码:
/// <summary> /// 获取评价详细信息 /// </summary> /// <param name="tID"></param> public void GetEvaluateMsg(string tID) { //差评 //http://club.jd.com/productpage/p-255742-s-1-t-3-p-0.html?callback=fetchJSON_comment98vv17736 //中评 //http://club.jd.com/productpage/p-255742-s-2-t-3-p-0.html?callback=fetchJSON_comment98vv17736 //好评 //http://club.jd.com/productpage/p-255742-s-3-t-3-p-0.html?callback=fetchJSON_comment98vv17736 try { string url = string.Format("http://club.jd.com/productpage/p-{0}-s-1-t-3-p-0.html", tID); string rtnMsg = HttpHelper.GetResponse(url, "get", string.Empty); List<EvaluateMsg> getMsgs = new List<EvaluateMsg>(); EvaluateMsg badMsg = JsonConvert.DeserializeObject<EvaluateMsg>(rtnMsg); if (badMsg != null && badMsg.comments != null && badMsg.comments.Count > 0) { getMsgs.Add(badMsg); int iCount = badMsg.productCommentSummary.poorCount; float iNum = (float)iCount / 10; int pagenum = (int)(iCount / 10); if (pagenum < iNum) { pagenum++; } if (pagenum > 1) { for (int i = 1; i <= pagenum; i++) { url = string.Format("http://club.jd.com/productpage/p-{0}-s-1-t-3-p-{1}.html", tID, i); rtnMsg = HttpHelper.GetResponse(url, "get", string.Empty); if (!string.IsNullOrEmpty(rtnMsg)) { badMsg = JsonConvert.DeserializeObject<EvaluateMsg>(rtnMsg); if (badMsg != null && badMsg.comments != null && badMsg.comments.Count > 0) { getMsgs.Add(badMsg); } } } } } if (getMsgs.Count > 0) { List<ProductMessage> msgs = new List<ProductMessage>(); foreach (var eMsg in getMsgs) { foreach (var item in eMsg.comments) { ProductMessage msg = new ProductMessage() { PID = tID, MsgType = 1, MsgContent = item.content, MsgUser = item.nickname, MsgUserLevel = item.userLevelName, MsgProvince = item.userProvince, MsgDate = item.creationTime }; msgs.Add(msg); } } DBHelper.GetInstance().WareMessagesAdd(msgs); } } catch (Exception ex) { OtCom.XLogErr(ex.Message); } }
把广告打起:杀京东 做最走心的京东价格监控软件 免费开源的价格监控软件 欢迎加入QQ群415014949一起讨论
时间: 2024-10-10 13:44:11