Exemple #1
0
        public static GoodsInfo GotDetailData(urlInfo ui)
        {
            GoodsInfo gif       = new GoodsInfo();
            string    detailUrl = "https://detail.tmall.com/item.htm?spm=a220m.1000858.1000725.5.rWDxsT&id=" + ui.dataId;

            GetAntaTmalData.driver.Navigate().GoToUrl(detailUrl);
            LoginHint(detailUrl, GetAntaTmalData.driver.PageSource);

            HtmlAgilityPack.HtmlDocument hd = new HtmlDocument();
            hd.LoadHtml(GetAntaTmalData.driver.PageSource);
            try
            {
                gif.TotalComment = uint.Parse(hd.DocumentNode.SelectSingleNode("//body/div[@id='page']/div[@id='content']/div[@id='detail']/div[@id='J_DetailMeta']/div[@class='tm-clear']/div[@class='tb-property']/div[@class='tb-wrap']/ul/li[2]/div/span[@class='tm-count']").InnerText);
                gif.MonSales     = int.Parse(hd.DocumentNode.SelectSingleNode("//body/div[@id='page']/div[@id='content']/div[@id='detail']/div[@id='J_DetailMeta']/div[@class='tm-clear']/div[@class='tb-property']/div[@class='tb-wrap']/ul/li[1]/div/span[@class='tm-count']").InnerText);
                string re    = hd.DocumentNode.SelectSingleNode("//*[@id='J_EmStock']").InnerText;
                string kucun = Regex.Match(re, @"\d+").Value;
                gif.Repertory = uint.Parse(kucun);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }


            //string jsonUrl = "https://dsr-rate.tmall.com/list_dsr_info.htm?itemId=" + ui.dataId + "&callback=jsonp220";
            //var comCount = GetCommInfo(jsonUrl);

            //string jsUrl = "https://mdskip.taobao.com/core/initItemDetail.htm?itemId=" + ui.dataId;
            //var saleInfo = GetSaledData(jsUrl);
            //GoodsInfo gif = new GoodsInfo();
            gif.Id         = ui.dataId;
            gif.IndexPrice = ui.indexPrice;
            //double price = 0.0;
            //foreach (var kv in saleInfo.defaultModel.itemPriceResultDO.priceInfo)
            //{
            //    price += kv.Value.price;
            //}
            //gif.AvePrice = price / saleInfo.defaultModel.itemPriceResultDO.priceInfo.Count;
            gif.TotalSales = ui.totalSales;
            //gif.MonSales = (int)saleInfo.defaultModel.sellCountDO.sellCount;
            //gif.Repertory = saleInfo.defaultModel.inventoryDO.TotalQuantity;
            gif.Name         = ui.name;
            gif.IndexComment = ui.indexComment;
            //gif.TotalComment = comCount;
            gif.LastUpdate = DateTime.Now;
            return(gif);
        }
Exemple #2
0
        public List <urlInfo> GetIndexList(string url, int pg, List <urlInfo> list)
        {
            HttpHelper http = new HttpHelper();

            http.DefaultHeadInfo.timeout           = 100000;
            http.DefaultHeadInfo.cookie_collection = new System.Net.CookieContainer();
            Uri uri = new Uri(url + pg);

            http.DefaultHeadInfo.cookie_collection.Add(uri, new System.Net.Cookie("t", "5b5f39b0ce4c5797e6f2e5a5abfdeeb0"));
            http.DefaultHeadInfo.cookie_collection.Add(uri, new System.Net.Cookie("_tb_token_", "vE0SSZDAO7Fe"));
            http.DefaultHeadInfo.cookie_collection.Add(uri, new System.Net.Cookie("cookie2", "fd45fc19ff278287a315b52e19b91ca6"));
            http.DefaultHeadInfo.header.Add("Accept-Encoding", " gzip, deflate, sdch, br");
            var page = http.Get(url + pg);
            int a    = 0;

            if (page.StatusCode != System.Net.HttpStatusCode.OK)
            {
                if (a > 5)
                {
                    return(null);
                }
                System.Threading.Thread.Sleep(2000);
                page = http.Get(url + pg);
            }
            HtmlDocument hd = new HtmlDocument();

            hd.LoadHtml(page.Html.Replace("\\", ""));
            var nodes = hd.DocumentNode.SelectNodes("//div[@class='J_TItems']//div[@class='item4line1']");

            if (nodes == null)
            {
                nodes = hd.DocumentNode.SelectNodes("//div[@class='J_TItems']//div[@class='item5line1']");
                if (nodes == null)
                {
                    return(null);
                }
            }
            for (int i = 0; i < nodes.Count - 2; i++)
            {
                var node_line = nodes[i].SelectNodes("./dl");
                for (int j = 0; j < node_line.Count; j++)
                {
                    var uf = new urlInfo();
                    uf.dataId     = UInt64.Parse(node_line[j].Attributes["data-id"].Value);
                    uf.name       = node_line[j].SelectSingleNode("./dd[@class='detail']/a").InnerText;
                    uf.detailUrl  = "http:" + node_line[j].SelectSingleNode("./dd[@class='detail']/a").Attributes["href"].Value;
                    uf.indexPrice = double.Parse(node_line[j].SelectSingleNode("./dd[@class='detail']/div[@class='attribute']/div[@class='cprice-area']//span[2]").InnerText);
                    try
                    {
                        uf.totalSales   = int.Parse(node_line[j].SelectSingleNode("./dd[@class='detail']/div[@class='attribute']/div[@class='sale-area']//span[1]").InnerText);
                        uf.indexComment = uint.Parse(Regex.Match(node_line[j].SelectSingleNode("./dd[@class='rates']/div[@class='title']").InnerText, @"\d+").Value);
                    }
                    catch { }
                    list.Add(uf);
                }
            }
            if (first)
            {
                var pgStr   = hd.DocumentNode.SelectSingleNode("//div[@class='filter clearfix J_TFilter']/p/b[@class='ui-page-s-len']").InnerText.Split('/')[1];
                int pgNodes = int.Parse(pgStr);
                if (pgStr != null)
                {
                    Console.WriteLine("共有 {0} 页", pgNodes);
                    first = false;
                    for (int un = 2; un <= pgNodes; un++)
                    {
                        System.Threading.Thread.Sleep(1000);
                        GetIndexList(url, un, list);
                        Console.WriteLine("第{0}页", un);
                    }
                }
            }
            return(list);
        }