How to get all possible image URLs from RSS feed item?

雨燕双飞 提交于 2019-12-01 20:46:04

I found the solution.

foreach (SyndicationElementExtension extension in f.ElementExtensions)
{
    XElement element = extension.GetObject<XElement>();

    if (element.HasAttributes)
    {
        foreach (var attribute in element.Attributes())
        {
            string value = attribute.Value.ToLower();
            if (value.StartsWith("http://") && (value.EndsWith(".jpg") || value.EndsWith(".png") || value.EndsWith(".gif") ))
            {
                   rssItem.ImageLinks.Add(value); // Add here the image link to some array
             }
        }                                
    }                            
}
XDocument xDoc = XDocument.Load("http://www.nydailynews.com/cmlink/NYDN.Article.rss");
XNamespace media = XNamespace.Get("http://search.yahoo.com/mrss/");

var images = xDoc.Descendants(media+"content")
    .Where(m=>m.Attribute("type").Value=="image/jpeg")
    .Select(m=>m.Attribute("url").Value)
    .ToArray();

--EDIT--

var images = feeds.Items
     .SelectMany(i => i.ElementExtensions
                       .Select(e => e.GetObject<XElement>().Attribute("url").Value)
                )
     .ToArray();

Gets a list of images from string

var text = "your text with image links";
Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?.(?:jpg|bmp|gif|png)", RegexOptions.IgnoreCase);
MatchCollection mactches = regx.Matches(text);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!