void WebClientHelper_EventBindSecondPageListNewsDelegateHandler(string temp) { if (temp == "单条新闻") { newsDetail = WebClientHelper.BondNewsDetail; //绑定页面数据 if (newsDetail.listPic == null) { this.GridNewsWithImage.Visibility = Visibility.Collapsed; this.GridNewsWithoutImage.Visibility = Visibility.Visible; pb1.Visibility = Visibility.Collapsed; //绑定GridNewsWithoutImage tb1Title.Text = newsDetail.title; tb1TimeAndWhere.Text = newsDetail.timeAndWhere; listNews.ItemsSource = newsDetail.listNews; } else { pb2.Visibility = Visibility.Collapsed; //绑定GridNewsWithImage this.GridNewsWithoutImage.Visibility = Visibility.Collapsed; this.GridNewsWithImage.Visibility = Visibility.Visible; tb2Title.Text = newsDetail.title; tb2TimeAndWhere.Text = newsDetail.timeAndWhere; listNews2.ItemsSource = newsDetail.listNews; listPic2.ItemsSource = newsDetail.listPic; } } else { return; } }
public static void StartGetMessage(string result, string state) { if (!string.IsNullOrEmpty(result)) { if (state.Substring(0, 1) == "0") { #region 获取滚动新闻列表 try { //开始获取有用数据 MatchCollection matchs = Regex.Matches(result, "<li>.*?</li>", RegexOptions.Singleline); //在此处可定义一个专门的委托返回下一页是否有数据 if (matchs.Count > 0)//证明本页有新闻内容 { //<li><span class="c_tit"><a href="http://finance.sina.com.cn/consume/gfpl/20120316/150911608637.shtml" target="_blank">国家食药监管局对麦当劳进行责任约谈 </a></span><span class="c_time">03月16日 15:09</span></li> listNews = new List<New>(); foreach (var item in matchs) { news = new New(); //<a\s+href\s*=\s*[|']?(?<uri>[^'>]*)[|']?[^<>]*>\s*(<[^<>]+>)*(?<title>[^<>]*)(<[^<>]+>)*\s*" + temp + "</a> MatchCollection matchs1 = Regex.Matches(item.ToString(), @"<a\s+href\s*=\s*[|']?(?<uri>[^'>]*)[|']?[^<>]*>\s*(<[^<>]+>)*(?<title>[^<>]*)(<[^<>]+>)*\s*</a>", RegexOptions.Singleline); news.url = GetNewUrl(matchs1[0].ToString()); string[] str = item.ToString().Split('>'); news.msg = GetStringWithoutTap(str[3].Substring(0, str[3].Length - 3)); news.time = str[6].Substring(0, str[6].Length - 6); listNews.Add(news);//获取了所有的大类 } if (listNews != null) { if (state.Substring(1, 1) == "0") { listBindNew = listNews; if (EventBindMainPageHubTileDelegateHandler != null) { EventBindMainPageHubTileDelegateHandler("央视新闻"); } } else if (state.Substring(1, 1) == "1") { listBindNewInternet = listNews; if (EventBindMainPageHubTileDelegateHandler != null) { EventBindMainPageHubTileDelegateHandler("网络新闻"); } } } } else//证明本页有新闻内容 { if (state.Substring(1, 1) == "0") { //listBindNew = listNews; if (EventBindMainPageHubTileDelegateHandler != null) { EventBindMainPageHubTileDelegateHandler("央视新闻无"); } } else if (state.Substring(1, 1) == "1") { //listBindNewInternet = listNews; if (EventBindMainPageHubTileDelegateHandler != null) { EventBindMainPageHubTileDelegateHandler("网络新闻无"); } } } } catch { return; } #endregion } else if (state.Substring(0, 1) == "1") { #region 获取图片列表 try { //开始获取有用数据 MatchCollection matchs = Regex.Matches(result, "<div.class=.picBox.*?</div>", RegexOptions.Singleline); //<div.class=.picBox.*?</div> 匹配首页16组图片 listPics = new List<Pictuer>(); foreach (var item in matchs) { pic = new Pictuer(); MatchCollection matchs1 = Regex.Matches(item.ToString(), @"[a-zA-z]+://[^\s]*", RegexOptions.Singleline); pic.url = matchs1[0].ToString().Substring(0, matchs1[0].ToString().Length - 1); pic.imageUrl = matchs1[1].ToString().Substring(0, matchs1[1].ToString().Length - 1); MatchCollection matchs2 = Regex.Matches(item.ToString(), "title=.+?s", RegexOptions.Singleline); pic.msg = matchs2[0].ToString().Split('"')[1].ToString(); MatchCollection matchs3 = Regex.Matches(item.ToString(), "<span>.*?</span>", RegexOptions.Singleline); pic.time = matchs3[0].ToString().Replace("(", ",").Replace(")", ",").Split(',')[1].ToString(); listPics.Add(pic); } if (listPics != null) { if (state.Substring(1, 1) == "0") { listBindPic = listPics; if (EventBindMainPageHubTileDelegateHandler != null) { EventBindMainPageHubTileDelegateHandler("央视图片"); } } else if (state.Substring(1, 1) == "1") { listBindPicInternet = listPics; if (EventBindMainPageHubTileDelegateHandler != null) { EventBindMainPageHubTileDelegateHandler("网络图片"); } } } } catch { return; } #endregion } else if (state == "3") { #region 获取消费滚动新闻列表 try { //开始获取有用数据 MatchCollection matchs = Regex.Matches(result, "<li>.*?</li>", RegexOptions.Singleline); //<li><span class="c_tit"><a href="http://finance.sina.com.cn/consume/gfpl/20120316/150911608637.shtml" target="_blank">国家食药监管局对麦当劳进行责任约谈 </a></span><span class="c_time">03月16日 15:09</span></li> listNews = new List<New>(); for (int i = 2; i < matchs.Count; i++) { news = new New(); //<a\s+href\s*=\s*[|']?(?<uri>[^'>]*)[|']?[^<>]*>\s*(<[^<>]+>)*(?<title>[^<>]*)(<[^<>]+>)*\s*" + temp + "</a> MatchCollection matchs1 = Regex.Matches(matchs[i].ToString(), @"<a\s+href\s*=\s*[|']?(?<uri>[^'>]*)[|']?[^<>]*>\s*(<[^<>]+>)*(?<title>[^<>]*)(<[^<>]+>)*\s*</a>", RegexOptions.Singleline); news.url = GetNewUrl(matchs1[0].ToString()); string[] str = matchs[i].ToString().Split('>'); news.msg = GetStringWithoutTap(str[2].Substring(0, str[2].Length - 3)); news.time = str[4].Substring(1, str[4].Length - 8); listNews.Add(news);//获取了所有的大类 } if (listNews != null) { listBindSpendNew = listNews; if (EventBindMainPageHubTileDelegateHandler != null) { EventBindMainPageHubTileDelegateHandler("消费新闻"); } } } catch { return; } #endregion } else if (state == "4") { #region 金融消费 try { //开始获取有用数据 listNews = new List<New>(); MatchCollection matchs = Regex.Matches(result, "315金融消费维权投诉曝光区.*?315金融消费维权投诉表格", RegexOptions.Singleline); MatchCollection matchs1 = Regex.Matches(matchs[0].ToString(), @"<div.class=.*?c_t_10.*?id=.*?cont_m.*?</div>", RegexOptions.Singleline); //\"><div class=\"c_t_10\" id=\"cont_m_9\">\r\n\n<h1> //<a href=\"http://finance.sina.com.cn/money/lcbgt/20120315/115611597201.shtml\" target=\"_blank\">中国人寿客户答谢会骗签保单</a></h1>\r\n //<p class=\"c_memo\">投诉公司:中国人寿保险股份有限公司<br>\r\n //投诉事件:国寿福禄满堂养老年金保险<br>\r\n //事件经过:上海市网友孙先生称,2011年8月份,国寿公司沈先生称,公司为了答谢老客户的支持,要举办联谊会。结果在推销员蛊惑下,孙先生签下了购买意向名:按照推销员给的字条上的话抄写一遍并签了名。 //</p>\r\n\n</div> foreach (var item in matchs1) { news = new New(); try { MatchCollection matchs2 = Regex.Matches(item.ToString(), "<a.*?</a>", RegexOptions.Singleline); //<a href=\"http://finance.sina.com.cn/money/lcbgt/20120315/115611597201.shtml\" target=\"_blank\">中国人寿客户答谢会骗签保单</a> if (matchs2.Count > 0) { news.url = GetNewUrl(matchs2[0].ToString()); if (matchs2.Count > 1) { news.backUrl = GetNewUrl(matchs2[1].ToString()); } news.time = GetStringWithoutTap(matchs2[0].ToString().Split('>')[1].ToString().Replace("</a", "")); } else { MatchCollection matchs4 = Regex.Matches(item.ToString(), "<h1.*?</h1>", RegexOptions.Singleline); news.time = GetStringWithoutTap(matchs4[0].ToString().Split('>')[1].Replace("</h1", "")); } } catch { return; } MatchCollection matchs3 = Regex.Matches(item.ToString(), "<p.*?</p>", RegexOptions.Singleline); //<p class=\"c_memo\">投诉公司:中国人寿保险股份有限公司<br>\r\n 投诉事件:国寿福禄满堂养老年金保险<br>\r\n 事件经过:上海市网友孙先生称,2011年8月份,国寿公司沈先生称,公司为了答谢老客户的支持,要举办联谊会。结果在推销员蛊惑下,孙先生签下了购买意向名:按照推销员给的字条上的话抄写一遍并签了名。</p> news.msg = matchs3[0].ToString().Split('"')[2].ToString().Replace("<br>\r\n", "").Replace(">", "").Replace("</p", ""); listNews.Add(news); } if (listNews != null) { listBindFinancialNew = listNews; if (EventBindMainPageHubTileDelegateHandler != null) { EventBindMainPageHubTileDelegateHandler("金融新闻"); } } } catch { return; } #endregion } else if (state == "2") { #region 获取单条新闻信息 try { newsDetail = new NewsDetail(); listPics = new List<Pictuer>(); MatchCollection matchsTitle = Regex.Matches(result, @"<h1.id=.artibodyTitle.*?</h1>", RegexOptions.Singleline); newsDetail.title = matchsTitle[0].ToString().Split('>')[1].ToString().Substring(0, matchsTitle[0].ToString().Split('>')[1].ToString().Length - 4); MatchCollection matchsTimeAndWhere = Regex.Matches(result, @"<div.class=.artInfo.>.*?</div>", RegexOptions.Singleline); newsDetail.timeAndWhere = matchsTimeAndWhere[0].ToString().Split('>')[6].ToString().Replace(" ", "").Replace("</span", ""); //判断是否存在>2个大<a></a> //>.*?< MatchCollection matchsTimeAndWhere2 = Regex.Matches(matchsTimeAndWhere[0].ToString(), @">.*?<", RegexOptions.Singleline); if (matchsTimeAndWhere2[7].ToString().Replace(">", "").Replace("<", "") == "") { newsDetail.timeAndWhere += matchsTimeAndWhere2[8].ToString().Replace(">", "").Replace("<", ""); } else { newsDetail.timeAndWhere += matchsTimeAndWhere2[7].ToString().Replace(">", "").Replace("<", ""); } MatchCollection matchs = Regex.Matches(result, @"<div.class=.blkContainerSblkCon.\sid=.artibody.>.*?<a.class=.icon_sina.", RegexOptions.Singleline); //获取新闻内容所在的div MatchCollection matchs1 = Regex.Matches(matchs[0].ToString(), "<img.*?src=.*?http.*?alt.*?>", RegexOptions.Singleline);//<img.*?> if (matchs1.Count > 0) { //匹配图片 可能多张 for (int i = 0; i < matchs1.Count; i++) { pic = new Pictuer(); MatchCollection matchs11 = Regex.Matches(matchs1[i].ToString(), @"[a-zA-z]+://[^\s]*", RegexOptions.Singleline); pic.imageUrl = matchs11[0].ToString().Split('"')[0].ToString(); MatchCollection matchs12 = Regex.Matches(matchs1[i].ToString(), @"alt=..+?""", RegexOptions.Singleline); pic.msg = GetStringWithoutTap(matchs12[0].ToString().Split('"')[1].ToString()); //matchs1[0].ToString().Split('"')[1].ToString(); //获取图片说明// //matchs1[0].ToString().Split('"')[3].ToString(); //获取图片地址//alt=..+?" listPics.Add(pic); } newsDetail.listPic = listPics; } else { newsDetail.listPic = null;//list为null } MatchCollection matchs2 = Regex.Matches(matchs[0].ToString(), "<p>.*?</p>", RegexOptions.Singleline); //匹配新闻 可能多条 if (matchs2.Count > 0) { listNews = new List<New>(); for (int i = 0; i < matchs2.Count; i++) { news = new New(); news.msg = GetStringWithoutTap(matchs2[i].ToString().Replace("<p>", "").Replace("</p>", ""));//获取新闻 listNews.Add(news); } newsDetail.listNews = listNews; } else { newsDetail.listNews.Add(new New { msg = "暂无消息" }); } if (newsDetail != null) { BondNewsDetail = newsDetail; if (EventBindSecondPageListNewsDelegateHandler != null) { EventBindSecondPageListNewsDelegateHandler("单条新闻"); } } } catch { return; } #endregion } } else { return; } }