/// <summary> /// 获取个人资料,邮箱、排名 /// </summary> /// <param name="profile"></param> /// <returns></returns> public Dictionary <string, string> getProfile(string profile) { Dictionary <string, string> rs = new Dictionary <string, string>(); string cookieString = CookieHelper.getCookie(); HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(profile, 10000, cookieString); string html = IOUtils.getContent(response); rs.Add("email", JsonMatch.GetJSONValue(html, "publicEmail")); rs.Add("rank", JsonMatch.GetJSONValue(html, "rank")); //MessageBox.Show("ok"); return(rs); }
private void getCommentUsers(string asin, int page) { progress(this, "ASIN=" + asin + ",获取第" + page + "页"); string url = "https://www.amazon.com/ss/customer-reviews/ajax/reviews/get/ref=cm_cr_arp_d_paging_btm_" + page; IDictionary <string, string> parameters = new Dictionary <string, string>(); parameters.Add("sortBy", ""); parameters.Add("reviewerType", ""); parameters.Add("formatType", ""); parameters.Add("filterByStar", ""); parameters.Add("pageNumber", page.ToString()); parameters.Add("filterByKeyword", ""); parameters.Add("shouldAppend", "undefined"); parameters.Add("deviceType", "desktop"); parameters.Add("reftag", "cm_cr_getr_d_paging_btm_" + page); parameters.Add("pageSize", "10"); parameters.Add("asin", asin); parameters.Add("scope", "reviewsAjax1"); HttpWebResponse response = HttpWebResponseUtility.CreatePostHttpResponse(url, parameters, 10000, Encoding.UTF8, CookieHelper.getCookie()); string content = IOUtils.getContent(response); string [] array = Regex.Split(content, "&&&", RegexOptions.IgnoreCase); foreach (string item in array) { if (item.IndexOf("#cm_cr-review_list") != -1) { //开始时间 //结束时间 //休眠=(休眠时间-(结束时间-开始时间))>0 //解析json JArray jarray = (JArray)JsonConvert.DeserializeObject(item); if (jarray[0].ToString().IndexOf("append") == -1) { continue; } string commentInfo = jarray[2].ToString(); Document doc = NSoupClient.Parse(commentInfo); Element element = doc.Select(".a-icon-star").First; //评分 int start = 0; if (element != null) { for (int i = 1; i <= 5; i++) { if (element.HasClass("a-star-" + i)) { start = i; break; } } } //昵称 element = doc.Select("a[data-hook=review-author]").First; if (element == null) { continue; } string nickName = element.Text(); string profile = "https://www.amazon.com" + element.Attr("href"); //获取个人资料 Dictionary <string, string> profileInfo = null; try { profileInfo = getProfile(profile); } catch (Exception e) { progress(this, "读取个人主页报错 profile=" + progress + " error =" + e.Message); } if (profileInfo == null) { continue; } string email = profileInfo["email"]; if (email != null && !"".Equals(email)) { //MessageBox.Show(email); } progress(this, "ASIN=" + asin + ",昵称=" + nickName + ",评分=" + start + ",邮箱=" + email); // Comment comment = new Comment(); comment.Star = start; comment.Email = email; comment.Rank = 0; comment.NickName = nickName; comment.Profile = profile; long beginTime = GetUnixTime(DateTime.Now); string rank = profileInfo["rank"]; if (rank != null) { rank = rank.Replace(",", ""); if (!rank.Equals("")) { comment.Rank = int.Parse(rank); } } this.onComment(comment); //结束时间-开始时间<=sleep long endTime = GetUnixTime(DateTime.Now); long value = endTime - beginTime; if (value <= sleep) { Thread.Sleep((int)(sleep - value)); } } } }