京东优惠叠加的获取
最近双十一,双十二,促销多的眼花缭乱,领了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

浙公网安备 33010602011771号