static void computerParam_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { try { if (e.Result != null) { MatchCollection matchParam = Regex.Matches(e.Result.ToString(), "【.*?<p>", RegexOptions.Singleline); //matchParam[0].ToString(); string[] str = matchParam[0].ToString().Replace("<br />\n", "●").Split('●'); listComputerParam = new List<ComputerParam>(); for (int i = 0; i < str.Length - 1; i++) { computerParam = new ComputerParam(); computerParam.strText = str[i].ToString(); listComputerParam.Add(computerParam); } if (EventBindMainPage1ComputerParamDelegateHandler != null) { EventBindMainPage1ComputerParamDelegateHandler(); } } } catch { return; } }
static void computerIndex_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { try { if (e.Result != null) { #region 数据获取 computerDetail = new ComputerDetail(); //匹配电脑名称 try { MatchCollection matchName = Regex.Matches(e.Result.ToString(), "</a>.*?综述?", RegexOptions.Singleline); computerDetail.computerName = matchName[0].ToString().Split('>')[matchName[0].ToString().Split('>').Length - 1].ToString().Substring(4, matchName[0].ToString().Split('>')[matchName[0].ToString().Split('>').Length - 1].ToString().Length - 10); //匹配图片 } catch { computerDetail.computerName = "没有数据"; } //匹配图片 try { MatchCollection matchImg = Regex.Matches(e.Result.ToString(), "<img.+?/>", RegexOptions.Singleline); MatchCollection imgUrl = Regex.Matches(matchImg[1].ToString(), "http.+jpg", RegexOptions.Singleline); computerDetail.computerImgUrl = imgUrl[0].ToString(); } catch { computerDetail.computerImgUrl = "image/404.jpg"; } //匹配价格 try { MatchCollection matchPic = Regex.Matches(e.Result.ToString(), @"¥\d+(.\d+万)?", RegexOptions.Singleline); if (matchPic.Count > 0) { computerDetail.computerPic = matchPic[0].ToString();//zol报价 } else { computerDetail.computerPic = "暂无数据"; } MatchCollection matchPicToPic = Regex.Matches(e.Result.ToString(), @"¥\d+.至.¥?\d+(.\d+万)?", RegexOptions.Singleline); //computerDetail.computerPicToPic = matchPic[1].ToString() + matchPic[2].ToString();//匹配商家报价//¥\d+.至.\d+ if (matchPicToPic.Count > 0) { computerDetail.computerPicToPic = matchPicToPic[0].ToString();//匹配商家报价 } else { computerDetail.computerPicToPic = "暂无报价"; } //¥\d+.至.\d+ //经销商报价还有5个 //匹配上市时间 //MatchCollection matchParam = Regex.Matches(e.Result.ToString(), "((上市时间)|(上市日期)|(操作系统)|(防抖性能)|(机身特性)).+?【", RegexOptions.Singleline); //string[] str = (matchParam[0].ToString().Substring(0, matchParam[0].ToString().Length - 1)).Replace("<br />\n", "●").Split('●'); MatchCollection matchParam = Regex.Matches(e.Result.ToString(), "】.+?【", RegexOptions.Singleline); if (matchParam.Count>0) { string[] str = (matchParam[0].ToString().Replace("<br />\n", "●").Split('●')); listComputerParam = new List<ComputerParam>(); for (int i = 1; i < str.Length - 1; i++) { computerParam = new ComputerParam(); computerParam.strText = str[i].ToString(); listComputerParam.Add(computerParam); } computerDetail.computerParams = listComputerParam; } else { listComputerParam = new List<ComputerParam>(); computerParam = new ComputerParam(); computerParam.strText = "暂不数据"; listComputerParam.Add(computerParam); computerDetail.computerParams = listComputerParam; } //匹配经销商 MatchCollection matchParamSeller = Regex.Matches(e.Result.ToString(), "(经销商报价.+?【)|(经销商报价.+?<br />)", RegexOptions.Singleline); if (matchParamSeller.Count > 0) { MatchCollection matchParamSellers = Regex.Matches(matchParamSeller[0].ToString(), @"<br.?/>.+?¥\d*", RegexOptions.Singleline); if (matchParamSellers.Count > 0) { int temp1 = 5; listSeller = new List<Seller>(); foreach (var item in matchParamSellers) { seller = new Seller(); //>.*?< MatchCollection matchParamSellerItem = Regex.Matches(item.ToString(), ">.*?<", RegexOptions.Singleline); if (matchParamSellerItem.Count > 0) { //经销商名称 //matchParamSellerItem[0].ToString().Substring(1,matchParamSellerItem[0].ToString().Length-1); string temp = matchParamSellerItem[0].ToString().Replace("\n", ""); seller.sellerName = temp.Substring(1, temp.Length - 2); //经销商联系方式 seller.sellerPhone = matchParamSellerItem[2].ToString().Substring(1, matchParamSellerItem[2].ToString().Length - 2); seller.sellerPrice = matchPic[matchPic.Count - temp1].ToString(); listSeller.Add(seller); temp1--; } else { seller.sellerName = "暂无数据"; seller.sellerPhone = "暂无数据"; seller.sellerPrice = "暂无数据"; listSeller.Add(seller); } } computerDetail.sellers = listSeller; //temp1 = 5; } else { listSeller = new List<Seller>(); seller = new Seller(); seller.sellerName = "暂无数据"; seller.sellerPhone = "暂无数据"; seller.sellerPrice = "暂无数据"; listSeller.Add(seller); } } else { listSeller = new List<Seller>(); seller = new Seller(); seller.sellerName = "暂无数据"; seller.sellerPhone = "暂无数据"; seller.sellerPrice ="暂无数据"; listSeller.Add(seller); } } catch { computerDetail.computerName = "暂无数据"; } #endregion //此处判断这次数据的userState switch (Convert.ToInt32(e.UserState.ToString().Split(',')[0]))//获取所属类别 { case 0://笔记本 computerDetail.computerIndex = Convert.ToInt32(e.UserState.ToString().Split(',')[1]); listBindComputerDetail.Add(computerDetail); if (listBindComputerDetail.Count == listComputerComputer.Count) { //循环赋值给 //System.Collections.Generic Comparison<ComputerDetail> com = PersonCompare; listBindComputerDetail.Sort(com); if (EventBindMainPageListComputerHotDelegateHandler != null) { EventBindMainPageListComputerHotDelegateHandler(Convert.ToInt32(e.UserState.ToString().Split(',')[0]));//将所属类别传进去 } } break; case 1://手机 computerDetail.computerIndex = Convert.ToInt32(e.UserState.ToString().Split(',')[1]); listBindPhoneDetail.Add(computerDetail); if (listBindPhoneDetail.Count == listComputerPhone.Count) { //循环赋值给 Comparison<ComputerDetail> com = PersonCompare; listBindPhoneDetail.Sort(com); if (EventBindMainPageListComputerHotDelegateHandler != null) { EventBindMainPageListComputerHotDelegateHandler(Convert.ToInt32(e.UserState.ToString().Split(',')[0]));//将所属类别传进去 } } break; case 2://平板电脑 computerDetail.computerIndex = Convert.ToInt32(e.UserState.ToString().Split(',')[1]); listBindTableComputerDetail.Add(computerDetail); if (listBindTableComputerDetail.Count == listComputerTableComputer.Count) { Comparison<ComputerDetail> com = PersonCompare; listBindTableComputerDetail.Sort(com); if (EventBindMainPageListComputerHotDelegateHandler != null) { EventBindMainPageListComputerHotDelegateHandler(Convert.ToInt32(e.UserState.ToString().Split(',')[0]));//将所属类别传进去 } } break; case 3://数码相机 computerDetail.computerIndex = Convert.ToInt32(e.UserState.ToString().Split(',')[1]); listBindCameraDetail.Add(computerDetail); if (listBindCameraDetail.Count == listComputerCamera.Count) { Comparison<ComputerDetail> com = PersonCompare; listBindCameraDetail.Sort(com); if (EventBindMainPageListComputerHotDelegateHandler != null) { EventBindMainPageListComputerHotDelegateHandler(Convert.ToInt32(e.UserState.ToString().Split(',')[0]));//将所属类别传进去 } } break; case 4://其他,而且是唯一的 computerDetail.computerIndex = Convert.ToInt32(e.UserState.ToString().Split(',')[1]); listBindOtherDetail.Add(computerDetail); if (listBindOtherDetail.Count == listComputerOther.Count) { Comparison<ComputerDetail> com = PersonCompare; listBindOtherDetail.Sort(com); if (EventBindMainPage2ComputerListDelegateHandler != null) { EventBindMainPage2ComputerListDelegateHandler(Convert.ToInt32(e.UserState.ToString().Split(',')[0]));//将所属类别传进去 } } break; } #region 其他 } else { return; } } catch { return; } #endregion }