Ejemplo n.º 1
0
        /// <summary>
        /// 查询商品描述符合度  来自于谷歌插件的算法
        /// </summary>
        /// <returns></returns>
        public static bool CheckProductYes(string id)
        {
            HttpHelper     http   = new HttpHelper();
            TBDetailResult result = new TBDetailResult();
            HttpItem       item   = new HttpItem()
            {
                URL    = "https://scenes.taobao.com/content/json/getItemDetailByUrl.do?appKey=jiyoujia&isNeedTaoke=true&isCheckItem=true&url=https://item.taobao.com/item.htm?id=" + id,
                Method = "get",
                Accept = "*/*",
            };
            var list = http.GetHtml(item).Html;
            var obj  = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(list);

            return(obj["errorMsg"].ToString().Trim() == "");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询商品详情(临时租用 可以查到创建时间)
        /// </summary>
        /// <returns></returns>
        public static TBDetailResult GetProductDetailFromApi(string productId)
        {
            HttpHelper     http   = new HttpHelper();
            TBDetailResult result = new TBDetailResult();
            HttpItem       item   = new HttpItem()
            {
                URL         = "http://3f4d1b-11.sh.1253485869.clb.myqcloud.com:8013/Q69341380.ashx",
                Method      = "POST",
                Accept      = "*/*",
                Postdata    = "type=itemget&numiid=" + productId + "&fields=created,title,nick,detail_url",
                ContentType = "application/x-www-form-urlencoded"
            };
            var list = http.GetHtml(item).Html;
            //{"item_get_response":{"item":{"created":"2014-06-10 23:23:46","detail_url":"https:\/\/item.taobao.com\/item.htm?id=39437375897&spm=2014.21281452.0.0","nick":"永结同心婚庆店","title":"喜庆红盆 喜庆用品 红色结婚脸盆新娘婚庆嫁妆红盆 鸳鸯喜盆"},"request_id":"11iedlw1h8qn7"}}
            var obj   = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(list);
            var items = (JObject)((obj)["item_get_response"])["item"];

            result.createTime = items["created"].ToString();
            result.goodsName  = items["title"].ToString();
            result.shopName   = items["nick"].ToString();
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取天猫商品详情 如天猫没有 则请求淘宝
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public static TBDetailResult GetDetailHtml(string productId)
        {
            var html       = HttpGetDetailHtml(productId);
            var result     = new TBDetailResult();
            var risNotFind = new Regex("302 Found");
            var isNotFind  = risNotFind.Match(html).Value;

            if (isNotFind.Length > 0)
            {//淘宝商品
                html = HttpGetDetailHtml(productId, "https://item.taobao.com");
                var rvideoId = new Regex(@"""videoId"":""(?<videoid>.*?)""", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
                var videoid  = rvideoId.Match(html).Groups["videoid"].Value;
                if (videoid == "")
                {
                    return(null);
                }
                var rtitle      = new Regex(@" data-title=""?(title).*?""", RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
                var rshopname   = new Regex(@"sellerNick\s+:.*?'(?<shopname>.*?)'", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
                var rsellerid   = new Regex(@"sellerId \s+:.*?'(?<sellerid>.*?)',", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
                var rshopscores = new Regex(@"<a href="".*?"" target=""_blank"" title="".*?"">.*?\n(?<shopscores>.*?)\n .*?  </a>", RegexOptions.Multiline);
                var rimg        = new Regex(@"<a href=""#""><img data-src=""(?<img>.*?)"" /></a>", RegexOptions.Singleline);
                var rgoodsname  = new Regex(@"data-title=""(?<title>.*?)""", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                //判断是否有data-size="400x400"属性 有则取dataSize的大小
                var rimgSize = new Regex(@"<img id=""J_ImgBooth"" .*? data-hasZoom="".*?"" data-size=""(?<datasize>.*?)""/>");
                var imgSize  = rimgSize.Match(html).Groups["datasize"].Value;
                //if (imgSize == "") {
                imgSize = "500x500";
                //}
                var   mimgs = rimg.Matches(html);
                Match mimg;  //取第五张张主图
                if (mimgs.Count >= 5)
                {
                    mimg = mimgs[4];
                }
                else
                {
                    mimg = mimgs[mimgs.Count - 1];
                }
                var oldimg = mimg.Groups["img"].Value;
                var ind    = oldimg.LastIndexOf('_');
                result.bigImg    = "http:" + oldimg.Substring(0, ind + 1) + imgSize + "q90.jpg";
                result.goodsUrl  = "https://item.taobao.com/item.htm?spm=a230r.1.14.28.59cfa6e5A93fSw&id=" + productId + "&ns=1&abbucket=5";
                result.shopName  = rshopname.Match(html).Groups["shopname"].Value;
                result.sellerId  = rsellerid.Match(html).Groups["sellerid"].Value;
                result.videoUrl  = "https://cloud.video.taobao.com/play/u/" + result.sellerId + "/p/1/e/6/t/1/" + videoid + ".mp4";
                result.goodsName = rgoodsname.Match(html).Groups["title"].Value;
                var mshopscores = rshopscores.Matches(html);
                var shopscores  = new List <string>();
                for (int i = 0; i < mshopscores.Count; i++)
                {
                    shopscores.Add(mshopscores[i].Groups["shopscores"].ToString().Trim());
                }
                result.shopScores = shopscores;
            }
            else
            {
                //天猫商品
                var rvideoIds = new Regex(@":""//cloud.video.taobao.com/.*?/t/./(?<video>.*?).swf", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
                var videoid   = rvideoIds.Match(html).Groups["video"].Value;
                //只要有视频的
                if (videoid == "")
                {
                    return(null);
                }
                var rshopname   = new Regex(@"<a class=""slogo-shopname"" href="".*?"" data-spm="".*?""><strong>(?<shopname>.*?)</strong></a>", RegexOptions.Singleline);
                var rsellerid   = new Regex("sellerId=(?<sellerid>.*?)&", RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace);
                var rshopscores = new Regex(@"<span class=""shopdsr-score-con"">(?<shopscores>.*?)</span>");  //描述  服务  物流
                var rtitle      = new Regex(@"""title"":""(?<title>.*?)""", RegexOptions.Singleline);
                var rimg        = new Regex(@"<a href=""#""><img src=""(?<img>.*?)"" /></a>", RegexOptions.Singleline);
                var rgoodsName  = new Regex(@"<meta name=""keywords"" content=""(?<title>.*?)""/>");

                var   mimgs = rimg.Matches(html);
                Match mimg;
                if (mimgs.Count >= 5)//取第五张张主图
                {
                    mimg = mimgs[4];
                }
                else
                {
                    mimg = mimgs[mimgs.Count - 1];
                }
                var oldimg = mimg.Groups["img"].Value;
                var ind    = oldimg.LastIndexOf('_');
                result.bigImg    = "http:" + oldimg.Substring(0, ind + 1) + "430x430q90.jpg";
                result.goodsUrl  = "https://detail.tmall.com/item.htm?spm=a230r.1.14.28.59cfa6e5A93fSw&id=" + productId + "&ns=1&abbucket=5";
                result.shopName  = rshopname.Match(html).Groups["shopname"].Value;
                result.sellerId  = rsellerid.Match(html).Groups["sellerid"].Value;
                result.goodsName = rgoodsName.Match(html).Groups["title"].Value;
                result.videoUrl  = "https://cloud.video.taobao.com/play/u/" + result.sellerId + "/p/1/e/6/t/1/" + videoid + ".mp4";
                var mshopscores = rshopscores.Matches(html);
                var shopscores  = new List <string>();
                for (int i = 0; i < mshopscores.Count; i++)
                {
                    shopscores.Add(mshopscores[i].Groups["shopscores"].ToString());
                }
                result.videoId    = videoid;
                result.shopScores = shopscores;
            }
            return(result);
        }