/// <summary> /// 分析数据 /// </summary> /// <param name="xmlDoc"></param> /// <returns></returns> public ObservableCollection<Product> Analysis(int siteId, int cityId, string xmlDoc) { ObservableCollection<Product> productList = new ObservableCollection<Product>(); HtmlDocument xml = new HtmlDocument(); xml.LoadHtml(xmlDoc.Replace("<![CDATA[", "").Replace("]]>", "")); HtmlNodeCollection dataNodeList = xml.DocumentNode.ChildNodes["response"].ChildNodes["deals"].ChildNodes; if (dataNodeList.Count > 0) { foreach (HtmlNode dataNode in dataNodeList) { if (dataNode.Name == "data") { Product product = new Product(); product._webSiteId = siteId; product._cityId = cityId; HtmlNodeCollection dealCollection = dataNode.ChildNodes["deal"].ChildNodes; product.Guid = dealCollection["deal_id"].InnerText; if (dealCollection["deal_desc"].InnerText.Length > 35) product.Title = "【" + dealCollection["website"].InnerText + "】" + dealCollection["deal_desc"].InnerText.Substring(0, 35) + "..."; else product.Title = "【" + dealCollection["website"].InnerText + "】" + dealCollection["deal_desc"].InnerText; product.Url = dealCollection["deal_url"].InnerText; product.WapUrl = dealCollection["deal_wap_url"].InnerText; product.Image = dealCollection["deal_img"].InnerText; product.SmallImage = dealCollection["deal_img"].InnerText; product._categoryId = Core.CategoryConvert.ConvertTo(dealCollection["deal_cate"].InnerText); //有问题 product.Detail = dealCollection["deal_desc"].InnerText; float value = 0; float.TryParse(dealCollection["value"].InnerText, out value); product.Value = value; product.Price = float.Parse(dealCollection["price"].InnerText); product.Rebate = float.Parse(dealCollection["rebate"].InnerText); product.Bought = dealCollection["sales_num"].InnerText; product.StartTime = Core.JsonTimeConvert.ConvertTo(dealCollection["start_time"].InnerText); product.EndTime = Core.JsonTimeConvert.ConvertTo(dealCollection["end_time"].InnerText); product.Tips = dealCollection["deal_tips"].InnerText; product.Range = dealCollection["deal_range"].InnerText; product.Address = dealCollection["deal_address"].InnerText; product.Longitude = dealCollection["deal_lng"].InnerText; product.Latitude = dealCollection["deal_lat"].InnerText; product.Seller = dealCollection["deal_seller"].InnerText; product.Phone = dealCollection["deal_phones"].InnerText; HtmlNodeCollection shopsCollection = dataNode.ChildNodes["shops"].ChildNodes; HtmlNodeCollection shopCollection = shopsCollection["shop"].ChildNodes; product.DpShopId = shopCollection["shop_dpid"].InnerText; product.Traffic = shopCollection["shop_trafficinfo"].InnerText; product.Collect = "未收藏"; product.CollectPic = "/Images/30xStar_Gray.png"; product.Time = DateTime.Now; productList.Add(product); } } } return productList; }
private void Add_ToDo(Product product) { product.WebSite = this; }
private void Delete_ToDo(Product product) { product.WebSite = null; }
/// <summary> /// 分析数据 /// </summary> /// <param name="xmlDoc"></param> /// <returns></returns> public ObservableCollection<Product> Analysis(int siteId, int cityId, string xmlDoc) { ObservableCollection<Product> productList = new ObservableCollection<Product>(); HtmlDocument xml = new HtmlDocument(); xml.LoadHtml(xmlDoc.Replace("<![CDATA[", "").Replace("]]>", "")); HtmlNodeCollection urlSetNodeList = xml.DocumentNode.LastChild.ChildNodes; if (urlSetNodeList.Count > 0) { foreach (HtmlNode urlNode in urlSetNodeList) { if (urlNode.Name == "url") { Product product = new Product(); HtmlNodeCollection urlNodeList = urlNode.ChildNodes; product.Url = urlNodeList["loc"].InnerText; product.WapUrl = urlNodeList["wap_url"].InnerText; product._webSiteId=siteId; product._cityId=cityId; HtmlNodeCollection displayNodeList = urlNodeList["data"].FirstChild.NextSibling.ChildNodes; product._categoryId = Core.CategoryConvert.ConvertFrom(displayNodeList["title"].InnerText); //todo product.Guid = displayNodeList["gid"].InnerText; if (displayNodeList["title"].InnerText.Length > 35) product.Title = "【" + displayNodeList["website"].InnerText + "】" + displayNodeList["title"].InnerText.Substring(0, 35) + "..."; else product.Title = "【" + displayNodeList["website"].InnerText + "】" + displayNodeList["title"].InnerText; product.Image = displayNodeList["image"].InnerText; product.SmallImage = displayNodeList["small_image"].InnerText; product.StartTime = Core.JsonTimeConvert.ConvertTo(displayNodeList["startTime"].InnerText); product.EndTime = Core.JsonTimeConvert.ConvertTo(displayNodeList["endTime"].InnerText); product.Value = float.Parse(displayNodeList["value"].InnerText,System.Globalization.NumberStyles.AllowDecimalPoint); product.Price = float.Parse(displayNodeList["price"].InnerText, System.Globalization.NumberStyles.AllowDecimalPoint); product.Rebate = float.Parse(displayNodeList["rebate"].InnerText); product.Bought = displayNodeList["bought"].InnerText; product.Detail = displayNodeList["title"].InnerText; #warning 拉手推荐问题 product.Major = false; //todo HtmlNodeCollection shopsNodeList = displayNodeList["shops"].ChildNodes; if (shopsNodeList.Count > 1) { HtmlNodeCollection shopNodeList = shopsNodeList[1].ChildNodes; //这里存在一个问题,目前只提取第一个商家 product.Seller = shopNodeList["name"].InnerText; product.Address = shopNodeList["addr"].InnerText; string[] phoneArray=shopNodeList["tel"].InnerText.Split('|'); if(phoneArray.Length>1) { foreach(string phone in phoneArray) { product.Phone += phone+","; } } else product.Phone=shopNodeList["tel"].InnerText; product.Longitude = shopNodeList["longitude"].InnerText; product.Latitude = shopNodeList["latitude"].InnerText; } product.Collect = "未收藏"; product.CollectPic = "/Images/30xStar_Gray.png"; product.Time = DateTime.Now; productList.Add(product); } } } return productList; }
private void Delete_ToDo(Product product) { product.ProductCity = null; }
private void Add_ToDo(Product product) { product.ProductCity = this; }
/// <summary> /// 分析数据 /// </summary> /// <param name="xmlDoc"></param> /// <returns></returns> public ObservableCollection<Product> Analysis(int siteId, int cityId, string xmlDoc) { ObservableCollection<Product> productList = new ObservableCollection<Product>(); HtmlDocument xml = new HtmlDocument(); xml.LoadHtml(xmlDoc.Replace("<![CDATA[", "").Replace("]]>", "")); HtmlNodeCollection dataNodeList = xml.DocumentNode.ChildNodes["response"].ChildNodes["deals"].ChildNodes; if (dataNodeList.Count > 0) { foreach (HtmlNode dataNode in dataNodeList) { if (dataNode.Name == "deal") { Product product = new Product(); product._webSiteId = siteId; product._cityId = cityId; HtmlNodeCollection dealCollection = dataNode.ChildNodes; product.Guid = dealCollection["id"].InnerText; if (dealCollection["title"].InnerText.Length > 35) product.Title = "【窝窝团】" + dealCollection["title"].InnerText.Substring(0, 35) + "..."; else product.Title = "【窝窝团】" + dealCollection["title"].InnerText; product.Url = dealCollection["deal_url"].InnerText; product.WapUrl = dealCollection["deal_url"].InnerText; product.Image = dealCollection["medium_image_url"].InnerText; product.SmallImage = dealCollection["small_image_url"].InnerText; product.StartTime = Core.JsonTimeConvert.ConvertTo(dealCollection["start_date"].InnerText); product.EndTime = Core.JsonTimeConvert.ConvertTo(dealCollection["end_date"].InnerText); if (dealCollection["is_top"].InnerText == "1") product.Major = true; else product.Major = false; float value = 0; float.TryParse(dealCollection["value"].InnerText, out value); product.Value = value; product.Price = float.Parse(dealCollection["price"].InnerText); product.Rebate = float.Parse(dealCollection["discount_percent"].InnerText); product.Bought = dealCollection["quantity_sold"].InnerText; product._categoryId = Core.CategoryConvert.ConvertFrom(dealCollection["title"].InnerText); product.Detail = dealCollection["title"].InnerText; HtmlNodeCollection shopsCollection = dealCollection["vendors"].ChildNodes; product.Seller = shopsCollection["vendor_name"].InnerText; HtmlNodeCollection shopCollection = shopsCollection["vendor"].ChildNodes; //product.DpShopId = shopCollection["shop_dpid"].InnerText; product.Range = shopCollection["area"].InnerText; product.Address = shopCollection["address"].InnerText; product.Longitude = shopCollection["lng"].InnerText; product.Latitude = shopCollection["lat"].InnerText; product.Phone = shopCollection["phone"].InnerText; product.Collect = "未收藏"; product.CollectPic = "/Images/30xStar_Gray.png"; product.Time = DateTime.Now; productList.Add(product); } } } return productList; }
private void Add_ToDo(Product product) { product.ProductCategory = this; }
/// <summary> /// 分析数据 /// </summary> /// <param name="xmlDoc"></param> /// <returns></returns> public ObservableCollection<Product> Analysis(int siteId, int cityId, string xmlDoc) { ObservableCollection<Product> productList = new ObservableCollection<Product>(); HtmlDocument xml = new HtmlDocument(); xml.LoadHtml(xmlDoc.Replace("<![CDATA[", "").Replace("]]>", "")); HtmlNodeCollection dataNodeList = xml.DocumentNode.ChildNodes["urlset"].ChildNodes; if (dataNodeList.Count > 0) { foreach (HtmlNode dataNode in dataNodeList) { if (dataNode.Name == "url") { Product product = new Product(); product._webSiteId = siteId; product._cityId = cityId; product.Url = dataNode.ChildNodes["loc"].InnerText; product.WapUrl = product.Url; product.Guid = product.Url; HtmlNodeCollection dealCollection = dataNode.ChildNodes["data"].ChildNodes["display"].ChildNodes; if (dealCollection["title"].InnerText.Length > 35) product.Title = "【" + dealCollection["website"].InnerText + "】" + dealCollection["title"].InnerText.Substring(0, 35) + "..."; else product.Title = "【" + dealCollection["website"].InnerText + "】" + dealCollection["title"].InnerText; if (!string.IsNullOrEmpty(dealCollection["category"].InnerText)) product._categoryId = int.Parse(dealCollection["category"].InnerText); else product._categoryId = 6; product.DpShopId = dealCollection["dpshopid"].InnerText; product.Address = dealCollection["address"].InnerText; if (dealCollection["major"].InnerText == "1") product.Major = true; else product.Major = false; product.Image = dealCollection["image"].InnerText; product.SmallImage = dealCollection["image"].InnerText; product.StartTime = Core.JsonTimeConvert.ConvertTo(dealCollection["startTime"].InnerText); product.EndTime = Core.JsonTimeConvert.ConvertTo(dealCollection["endTime"].InnerText); float value = 0; float.TryParse(dealCollection["value"].InnerText, out value); product.Value = value; product.Price = float.Parse(dealCollection["price"].InnerText); product.Rebate = float.Parse(dealCollection["rebate"].InnerText); product.Bought = dealCollection["bought"].InnerText; product.Detail = dealCollection["title"].InnerText; HtmlNodeCollection shopsCollection = dealCollection["shops"].ChildNodes; HtmlNodeCollection shopCollection = shopsCollection["shop"].ChildNodes; product.Longitude = shopCollection["longitude"].InnerText; product.Latitude = shopCollection["latitude"].InnerText; product.Seller = shopCollection["name"].InnerText; string[] phoneArray = shopCollection["tel"].InnerText.Split('|'); if (phoneArray.Length > 1) { foreach (string phone in phoneArray) { product.Phone += phone + ","; } } else product.Phone = shopCollection["tel"].InnerText; product.Range = shopCollection["area"].InnerText; product.Traffic = shopCollection["direction"].InnerText; product.Collect = "未收藏"; product.CollectPic = "/Images/30xStar_Gray.png"; product.Time = DateTime.Now; productList.Add(product); } } } return productList; }