如何从RSS源项目的所有可能的图片网址? [英] How to get all possible image URLs from RSS feed item?
本文介绍了如何从RSS源项目的所有可能的图片网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用这个例子来获取图像的URL从 HTTP://www.nydailynews .COM / cmlink / NYDN.Article.rss
但没有成功。
ü可以帮助我找到正确的方式通过 SyndicationItem
类会从RSS源项目的所有可能的图片网址?
有解决办法草案<一href="http://stackoverflow.com/questions/319591/reading-non-standard-elements-in-a-syndicationitem-with-syndicationfeed">here但我想应该更通用的解决方案。
感谢您!
名单,其中,RssFeedItem&GT;的RSSItems =新的名单,其中,RssFeedItem&GT;();
流流= e.Result;
XmlReader的响应= XmlReader.Create(流);
SyndicationFeed馈送= SyndicationFeed.Load(响应);
的foreach(在feeds.Items SyndicationItem F)
{
RssFeedItem的RSSItem =新RssFeedItem();
rssItem.Description = f.Summary.Text;
的foreach(SyndicationLink圈地f.Links.Where&LT; SyndicationLink&GT;(X =&GT; x.RelationshipType ==圈地))
{
乌里URL = enclosure.Uri;
长长度= enclosure.Length;
字符串mediaType的= enclosure.MediaType;
rssItem.ImageLinks.Add(url.AbsolutePath);
}
}
解决方案
我找到了解决办法。
的foreach(在f.ElementExtensions SyndicationElementExtension扩展)
{
的XElement元= extension.GetObject&LT;的XElement&GT;();
如果(element.HasAttributes)
{
的foreach(在element.Attributes var属性())
{
字符串值= attribute.Value.ToLower();
如果(value.StartsWith(HTTP://,。巴,。GIF)及;&安培(value.EndsWith(。JPG)|| value.EndsWith()|| value.EndsWith()) )
{
rssItem.ImageLinks.Add(值); //此处添加图片链接到一些数组
}
}
}
}
I try to use this example to get images urls from http://www.nydailynews.com/cmlink/NYDN.Article.rss
but no success
Could u help me to find all correct ways to gets all possible image URLs from RSS feed item by SyndicationItem
class?
There is draft solution here but I guess should be more generic solution.
Thank you!
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;
foreach (SyndicationLink enclosure in f.Links.Where<SyndicationLink>(x => x.RelationshipType == "enclosure"))
{
Uri url = enclosure.Uri;
long length = enclosure.Length;
string mediaType = enclosure.MediaType;
rssItem.ImageLinks.Add(url.AbsolutePath);
}
}
解决方案
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
}
}
}
}
这篇关于如何从RSS源项目的所有可能的图片网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文