【问题标题】:How to read a image url from a rss with syndicationFeed?如何使用 syndicationFeed 从 rss 中读取图像 url?
【发布时间】:2011-10-28 12:35:41
【问题描述】:

如何获取图片地址?假设标签是

    <media:thumbnail url="http://img.youtube.com/vi/y6_-cLWwEU0/default.jpg" width="120"
 height="90" />

在 syndicationFeed 中使用 syndicationItem?

我有这样的事情

 Stream stream = e.Result;
                    XmlReader response = XmlReader.Create(stream);
                    SyndicationFeed feeds = SyndicationFeed.Load(response);
                    foreach (SyndicationItem ff in feeds.Items)
                    {

                        RssItem rssItem = new RssItem(ff.Title.Text, ff.Summary.Text, ff.PublishDate.ToString(), ff.Links[0].Uri.AbsoluteUri, **ff.image?????** );
                        rssItems.Add(rssItem);
                    }

有什么帮助吗??

【问题讨论】:

标签: c# image-processing syndication


【解决方案1】:

例如,Google RSS 将所有图像保存在一个摘要中。

所以你可以通过这段代码提取它:

List<RssFeedItem> rssItems = new List<RssFeedItem>();
                    Stream stream = e.Result;
                    XmlReader response = XmlReader.Create(stream);
                    SyndicationFeed feeds = SyndicationFeed.Load(response);
                    foreach (SyndicationItem f in feeds.Items)
                    {
                        RssFeedItem rssItem = new RssFeedItem();

                        rssItem.Description = f.Summary.Text;

 const string rx =  @"(?<=img\s+src\=[\x27\x22])(?<Url>[^\x27\x22]*)(?=[\x27\x22])"; 
                        foreach (Match m in Regex.Matches(f.Summary.Text, rx, RegexOptions.IgnoreCase | RegexOptions.Multiline))
                        {
                            string src = m.Groups[1].Value;
                            if (src.StartsWith("//")) // Google RSS has it
                            {
                                src = src.Replace("//", "http://");
                            }

                            rssItem.ImageLinks.Add(src);
                        }

【讨论】:

    【解决方案2】:

    我也需要一个解决方案,我是这样使用的:

    foreach (SyndicationItem item in feed.Items)
    {
       int s,f;
            s = item.Summary.Text.IndexOf("<");
            f = item.Summary.Text.IndexOf("/>");
    
            if (f != -1)
                div1.InnerHtml += "</br>photo:" + item.Summary.Text.Substring(s, f + 1 - s);
    }
    

    我从摘要中提取img;

    【讨论】:

      【解决方案3】:

      流流 = e.Result;

              XmlReader response = XmlReader.Create(stream);
      
              SyndicationFeed feeds = SyndicationFeed.Load(response);
      
              foreach (SyndicationItem item in feeds.Items)
              {
                  if (item.ElementExtensions.Where(p => p.OuterName == "thumbnail").Count() != 0)
                  {
                      string imgPath = item.ElementExtensions.Where(p => p.OuterName == "thumbnail").First().GetObject<XElement>().Attribute("url").Value;
                      MessageBox.Show(imgPath); //use it to show the img in DIV or whereever you wish.
                  }
      
              }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-03-04
        • 1970-01-01
        • 2014-10-23
        • 1970-01-01
        • 2012-05-20
        • 1970-01-01
        • 1970-01-01
        • 2011-09-28
        相关资源
        最近更新 更多