2011-10-28 54 views
4

如何獲取圖片網址?假設標籤在使用syndicationFeed是syndicationItem如何使用syndicationFeed從rss中讀取圖片url?

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

我有這樣的事情

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); 
        } 

任何幫助?

+0

我有一個類似的問題,並使用代碼我張貼[這裏]解決[1] [1]:http://stackoverflow.com/questions/8220148/how-to-訪問的URL-ATTR-的-mediathumbnail和 - mediacontent元素合RSS饋送/ 8220455#8220455 –

回答

0

我還需要一種解決方案,我使用的是這樣的:

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;

0

例如,Google RSS將所有圖像保存在一段時間內。

所以U可以通過此代碼提取它:

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); 
         } 
1

流stream = 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. 
      } 

     }