Пример #1
0
        /// <summary>
        /// 获取评论,返回有邮箱的
        /// </summary>
        /// <param name="asin"></param>
        /// <returns></returns>
        public void getComment(string asin)
        {
            progress(this, "准备解析ASIN=" + asin);
            List <Comment> comments = new List <Comment>();

            //获取评论页数
            string url = "https://www.amazon.com/product-reviews/" + asin;

            string cookie = CookieHelper.getCookie();

            HttpWebResponse response = HttpWebResponseUtility.CreateGetHttpResponse(url, 10000, cookie);

            Encoding encode = System.Text.Encoding.GetEncoding("utf-8");

            Stream stream = response.GetResponseStream();


            if (response.ContentEncoding.ToLower().Contains("gzip"))
            {
                //gzip格式
                stream = new GZipStream(stream, CompressionMode.Decompress);
            }


            //如果速度太快,亚马逊返回503,就暂停程序5-10分钟

            string html;

            using (System.IO.StreamReader sr = new System.IO.StreamReader(stream, Encoding.UTF8))
            {
                html = sr.ReadToEnd();
            }

            Document doc     = NSoupClient.Parse(html);
            Element  element = doc.Select(".a-pagination").First;

            int page = 0;

            if (element != null)
            {
                element = doc.Select(".a-last").First;
                element = element.PreviousElementSibling;
                string text = element.Text().Replace(" ", "");

                page = int.Parse(text);
            }
            progress(this, "解析成功ASIN=" + asin + ",评论页数=" + page);

            for (int i = 1; i <= page; i++)
            {
                try
                {
                    // 获取其他页
                    getCommentUsers(asin, i);
                }
                catch (Exception e) {
                    progress(this, "读取第" + i + "页评论失败," + e.Message);
                }
            }
        }
Пример #2
0
        /// <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);
        }