public WeiXin_Item(WeiPublicEntity entity) { InitializeComponent(); WeiPublicEntity = entity; }
public void GetEntityList(string htmlUri) { try { weiPublickList.Clear(); String html = HtmlTag.GetHtmlinfo(htmlUri); //List<HtmlTag> tags1 = HtmlTag.FindTagByAttr(html, "div", "id", "history"); //var match = regex.Matches(html); List <HtmlTag> tags = HtmlTag.FindTagByAttr(html, "script", "type", "text/javascript"); string content = tags[tags.Count - 1].InnerHTML; string pattern = "var msgList = '{"; string tt = content.Substring(content.IndexOf(pattern) + pattern.Length); string[] sArr = tt.Split(new string[] { ""title"" }, StringSplitOptions.RemoveEmptyEntries); //string[] pse = tt.Split(tt, @"","digest":"" , RegexOptions.IgnoreCase); for (int i = 0; i < sArr.Length; i++) { sArr[i] = sArr[i].Replace(""", ""); sArr[i] = sArr[i].Replace("\\\\/", "/"); string[] dsc = sArr[i].Split(new string[] { ";,;" }, StringSplitOptions.RemoveEmptyEntries); if (i != 0) { WeiPublicEntity entity = new WeiPublicEntity(); for (int j = 0; j < dsc.Count(); j++) { if (j == 0) { entity.Title = dsc[j].Replace(";:;", string.Empty); } else if (j == 1) { entity.Content = dsc[j].Replace("digest;:;", string.Empty).Replace(" ", string.Empty).Replace("\\\\n", string.Empty); } else if (j == 3) { string P1 = dsc[j].Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries)[1]; entity.SourseUrl = "http://mp.weixin.qq.com/" + P1.Replace("amp;", string.Empty); } else if (j == 5) { string P2 = dsc[j].Split(new string[] { "cover;:;" }, StringSplitOptions.RemoveEmptyEntries)[0]; //P2 = P2.Replace("\"\"", "\\"); entity.ImageUrl = P2; } } this.Dispatcher.BeginInvoke(new Action(() => { WeiXin_Item III = new WeiXin_Item(entity); III.txtTitle.Text = entity.Title; III.txtContent.Text = entity.Content; III.img.Source = new BitmapImage(new Uri(entity.ImageUrl)); listBox.Items.Add(III); })); weiPublickList.Add(entity); } } } catch (Exception ex) { } }