zoukankan      html  css  js  c++  java
  • 捕获RSS新闻,远程获取

     public static string GetRssNews(string url,int count)
        {
            StringBuilder sb = new StringBuilder();
            WebRequest myRequest = WebRequest.Create(url);
            WebResponse myResponse = myRequest.GetResponse();

            Stream rssStream = myResponse.GetResponseStream();
            XmlDocument rssDoc = new System.Xml.XmlDocument();
            rssDoc.Load(rssStream);

            XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");

            string title = "";
            string link = "";
            string pubDate = "";
            sb.Append("<AllNews>");
            if (rssItems.Count > 0)
            {
                int num = 0;
                if (rssItems.Count >= count)
                {
                    num = count;
                }
                else
                {
                    num = rssItems.Count;
                }
                sb.Append("<newsCount>" + num.ToString() + "</newsCount>");
                for (int i = 0; i < num; i++)
                {
                    XmlNode rssDetail = rssItems.Item(i).SelectSingleNode("title");
                    if (rssDetail != null)
                    {
                        title =InsApp.word.CreateCode.CutStr(rssDetail.InnerText.ToString(),44);
                    }
                    else
                    {
                        title = "【点击查看新闻】";
                    }

                    rssDetail = rssItems.Item(i).SelectSingleNode("link");
                    if (rssDetail != null)
                    {
                        link = rssDetail.InnerText;
                    }
                    else
                    {
                        link = "";
                    }

                    rssDetail = rssItems.Item(i).SelectSingleNode("pubDate");
                    if (rssDetail != null)
                    {
                        pubDate = rssDetail.InnerText;
                    }
                    else
                    {
                        pubDate = "";
                    }
                    sb.Append("<News>");
                    sb.Append("<title>");
                    sb.Append(title);
                    sb.Append("</title>");
                    sb.Append("<link>");
                    sb.Append(link);
                    sb.Append("</link>");
                    sb.Append("<pubDate>");
                    sb.Append(pubDate);
                    sb.Append("</pubDate>");
                    sb.Append("</News>");
                }
            }
            else
            {
                sb.Append("<newsCount>0</newsCount>");
            }
            sb.Append("</AllNews>");

            return sb.ToString();
        }

  • 相关阅读:
    逆向工具的使用
    linux下用crunch工具生成密码
    Bugku--web-wp
    stegsolve.jar压缩包打开和使用方法
    华为eNSP无限井号#解决方法
    后渗透之meterpreter使用攻略
    后渗透2
    Raid磁盘阵列存储原理-数据恢复思路分析
    Office文档损坏或乱码如何修复
    遇到ZFS文件系统如此棘手的问题,这种办法简单又高效!
  • 原文地址:https://www.cnblogs.com/hqbird/p/1318276.html
Copyright © 2011-2022 走看看