京東優惠疊加的獲取


最近雙十一,雙十二,促銷多的眼花繚亂,領了n多優惠卷,為了合理湊單實在是浪費了好多時間。

於是這幾天寫了一個小工具,可以分析優惠卷湊單頁里所有商品都參加哪些活動,這樣能節約我們湊單的時間。

可以快速找到 2件5折 又同時參加 199-100 活動的商品

 

 

這樣就可以開心的剁手啦

這里我借鑒了很多前輩的經驗

大神1:http://www.cnblogs.com/asxinyu/p/CSharp_HtmlAgilityPack_XPath_Weather_Data.html

大神2:https://www.cnblogs.com/jjg0519/p/6702833.html

大神3:https://www.cnblogs.com/cpcpc/archive/2012/09/10/2679098.html

大神4:https://blog.csdn.net/xing851483876/article/details/80817578

大神5:http://www.cnblogs.com/xxue/p/9977801.html

 

然后整理了一下各位大神的代碼,寫出這個小軟件。

編碼很多年,水平實在抱歉。

這個是獲取優惠頁最大頁數。

public int getMaxpage(string htmlstr)
        {
            int maxpage = 0;
            try
            {
                string html = htmlstr;
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(html);
                string goodClass = "//div[@id='J_topPage']";
                //string goodClass = @"//*[@class='gl-item']/dl/dd";
                HtmlNodeCollection noneNodeList = doc.DocumentNode.SelectNodes(goodClass);
                foreach (var node in noneNodeList)
                {
                    JDspxx jdspxx = new JDspxx();
                    HtmlDocument docChild = new HtmlDocument();
                    docChild.LoadHtml(node.OuterHtml);

                    var dc = docChild.DocumentNode.SelectSingleNode("//i");
                    maxpage = int.Parse(dc.InnerText);                    
                }
                return maxpage;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return maxpage;
        }  

 

這個是獲取商品信息

public List<JDspxx> reHtml(string htmlstr)
        {
            List<JDspxx> jdlist = new List<JDspxx>();
            try
            {
                string html = htmlstr;
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(html);
                string goodClass = "//li[@class='gl-item']";
                //string goodClass = @"//*[@class='gl-item']/dl/dd";
                HtmlNodeCollection noneNodeList = doc.DocumentNode.SelectNodes(goodClass);
                foreach (var node in noneNodeList)
                {
                    JDspxx jdspxx = new JDspxx();
                    HtmlDocument docChild = new HtmlDocument();
                    docChild.LoadHtml(node.OuterHtml);

                    string spmc = "//div[@class='p-name p-name-type-2']";
                    HtmlNodeCollection listspmc = docChild.DocumentNode.SelectNodes(spmc);
                    {
                        HtmlDocument docChild1 = new HtmlDocument();
                        docChild1.LoadHtml(listspmc[0].OuterHtml);
                        jdspxx.url = listspmc[0].ChildNodes[1].Attributes["href"].Value;

                        var dc = docChild1.DocumentNode.SelectSingleNode("//em");
                        jdspxx.spmc = dc.InnerText;
                    }

                    string price = "//div[@class='p-price']";
                    HtmlNodeCollection listprice = docChild.DocumentNode.SelectNodes(price);
                    {
                        HtmlDocument docChild1 = new HtmlDocument();
                        docChild1.LoadHtml(listprice[0].OuterHtml);
                        var dc = docChild1.DocumentNode.SelectSingleNode("//i");
                        jdspxx.price = dc.InnerText;
                    }


                    string yhxx = "//div[@class='p-icons']";
                    HtmlNodeCollection listyhxx = docChild.DocumentNode.SelectNodes(yhxx);
                    {
                        HtmlDocument docChild1 = new HtmlDocument();
                        docChild1.LoadHtml(listyhxx[0].OuterHtml);
                        var dclist = docChild1.DocumentNode.SelectNodes("//i");
                        List<Yhxx> yhlist = new List<Yhxx>();
                        if (dclist != null)
                        {
                            foreach (var dc in dclist)
                            {
                                Yhxx yh = new Yhxx();
                                yh.yh = dc.InnerText;
                                yhlist.Add(yh);
                                if (!Yhmc.yhmc.Contains(dc.InnerText))
                                {
                                    Yhmc.yhmc.Add(dc.InnerText);
                                }
                            }
                        }
                        jdspxx.yhlist = yhlist;
                    }

                    jdlist.Add(jdspxx);
                }
                return jdlist;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return jdlist;
        }

  

 軟件下載地址

鏈接: https://pan.baidu.com/s/1p-kV0w11PpA6jNjsjhwEfw 提取碼: c5gu 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM