private void RefreshNews()
{
System.Xml.XmlTextReader xtr = new System.Xml.XmlTextReader("http://info.xzsec.com/profiler/files/homepage/news.xml");
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.Load(xtr);
System.Xml.XmlNode xn = xd.GetElementsByTagName("subject").Item(0);
int j = 0;
foreach (System.Xml.XmlNode xn_tem in xn.ChildNodes)
{
if (!this.IsExist(xn.ChildNodes.Item(j).Attributes["name"].Value))
{
CMS.BLL.NewsManage nm = new CMS.BLL.NewsManage();
CMS.Model.CMS_NewsT nt = new CMS.Model.CMS_NewsT();
nt.title = xn_tem.Attributes["name"].Value;
nt.content = this.getbody(xn_tem.Attributes["value"].Value);
nt.kindID = "35";
nt.createTime = DateTime.Now;
nt.modifyTime = DateTime.Now;
nt.state = 1;
nm.ModelObj = nt;
nm.Insert();
}
j++;
}
xtr.Close();
}
private string getbody(string id)
{
string url = @"http://info.xzsec.com/profiler/NewsDetail.aspx?group=xzsec&id=" + id;
System.Net.WebClient wc = new System.Net.WebClient();
byte[] pagedata = wc.DownloadData(url);
//转换字符、
string result = System.Text.Encoding.Default.GetString(pagedata);
int bodyStart = result.IndexOf(">", result.IndexOf("<body")) + 1;
int bodyStart2 = result.LastIndexOf("相关新闻") + 1;
int bodyStart3 = result.IndexOf("table", bodyStart2);
return result.Substring(bodyStart, result.IndexOf("</body>") - bodyStart - (result.Length - bodyStart3)).Replace("<font style=/"FONT-WEIGHT: bolder; FONT-SIZE: x-small; FONT-FAMILY: 宋体/">相关新闻</font>", "").Replace("<HR width=/"75%/" size=/"1/">", "");
}