读取chinanews新闻列表及内容
http://www.chinanews.com/rss/scroll-news.xml%22,//热点
"http://www.chinanews.com/rss/finance.xml%22,//财经
"http://www.chinanews.com/rss/sports.xml%22,//体育
"http://www.chinanews.com/rss/ent.xml%22,//娱乐
"http://www.chinanews.com/rss/health.xml%22,//健康
"http://www.chinanews.com/rss/auto.xml%22,//汽车
"http://www.chinanews.com/rss/society.xml%22,//社会
};
string[] urilist ={ ""http://www.chinanews.com/rss/finance.xml%22,//财经
"http://www.chinanews.com/rss/sports.xml%22,//体育
"http://www.chinanews.com/rss/ent.xml%22,//娱乐
"http://www.chinanews.com/rss/health.xml%22,//健康
"http://www.chinanews.com/rss/auto.xml%22,//汽车
"http://www.chinanews.com/rss/society.xml%22,//社会
};
private void ReadNews(string uri, ushort type)
{
try
{
string xml = NetHelper.ReadHtml(uri, Encoding.GetEncoding("gb2312"));
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
Dictionary<ushort, NewsEntity> newslist = new Dictionary<ushort, NewsEntity>();
XmlNodeList list = doc.SelectNodes("rss/channel/item");
for (int i = 0; i < list.Count; i++)
{
string title = System.Helpers.XmlHelper.GetChileNode(list[i], "title").InnerText.Replace("(图)", "").Replace("(组图)", "").Replace("(图)", "");
string link = System.Helpers.XmlHelper.GetChileNode(list[i], "link").InnerText;
string result = "";
int end = 0;
string html = NetHelper.ReadHtml(link, Encoding.Default);
int start = html.IndexOf("<div class=left_zw>");
if (start > 0)
end = html.IndexOf("<!--正文-->", start);
result = html.Substring(start, end - start);
int _end = 0;
int _start = result.IndexOf(@"<div id=""function_code_page"">");
if (_start > 0)
_end = result.IndexOf("</div>", _start);
string pageStr = result.Substring(_start, _end - _start);
result = result.Replace(pageStr, "");
result = Regex.Replace(result, "\r", "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "\n", "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "<.*?>", "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"&(.{2,6});", "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "\r{2,}", "\r", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "\t{2,}", "\t", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"\s{2,}", "", RegexOptions.IgnoreCase);
Console.WriteLine(result);
result = result.Trim('\r', '\n').TrimEnd();
if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(result))
{
{
try
{
string xml = NetHelper.ReadHtml(uri, Encoding.GetEncoding("gb2312"));
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
Dictionary<ushort, NewsEntity> newslist = new Dictionary<ushort, NewsEntity>();
XmlNodeList list = doc.SelectNodes("rss/channel/item");
for (int i = 0; i < list.Count; i++)
{
string title = System.Helpers.XmlHelper.GetChileNode(list[i], "title").InnerText.Replace("(图)", "").Replace("(组图)", "").Replace("(图)", "");
string link = System.Helpers.XmlHelper.GetChileNode(list[i], "link").InnerText;
string result = "";
int end = 0;
string html = NetHelper.ReadHtml(link, Encoding.Default);
int start = html.IndexOf("<div class=left_zw>");
if (start > 0)
end = html.IndexOf("<!--正文-->", start);
result = html.Substring(start, end - start);
int _end = 0;
int _start = result.IndexOf(@"<div id=""function_code_page"">");
if (_start > 0)
_end = result.IndexOf("</div>", _start);
string pageStr = result.Substring(_start, _end - _start);
result = result.Replace(pageStr, "");
result = Regex.Replace(result, "\r", "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "\n", "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "<.*?>", "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"&(.{2,6});", "", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "\r{2,}", "\r", RegexOptions.IgnoreCase);
result = Regex.Replace(result, "\t{2,}", "\t", RegexOptions.IgnoreCase);
result = Regex.Replace(result, @"\s{2,}", "", RegexOptions.IgnoreCase);
Console.WriteLine(result);
result = result.Trim('\r', '\n').TrimEnd();
if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(result))
{
}
}
}
}
catch
{
catch
{
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)