我想从这个 URL 中提取数据:http ://rss.cnn.com/rss/edition.rss
所以每个项目看起来像这样:
<item>
<title><![CDATA[Ireland stuns England at home of cricket]]></title>
<description><![CDATA[From World Cup glory to utter humiliation in the space of 10 days.]]></description>
<link>https://www.cnn.com/2019/07/24/sport/england-ireland-cricket-spt-intl/index.html</link>
<guid isPermaLink="true">https://www.cnn.com/2019/07/24/sport/england-ireland-cricket-spt-intl/index.html</guid>
<pubDate>Wed, 24 Jul 2019 13:17:56 GMT</pubDate>
<media:group>
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-super-169.jpg" height="619" width="1100" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-large-11.jpg" height="300" width="300" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-vertical-large-gallery.jpg" height="552" width="414" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-video-synd-2.jpg" height="480" width="640" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-live-video.jpg" height="324" width="576" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-t1-main.jpg" height="250" width="250" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-vertical-gallery.jpg" height="360" width="270" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-story-body.jpg" height="169" width="300" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-t1-main.jpg" height="250" width="250" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-assign.jpg" height="186" width="248" />
<media:content medium="image" url="https://cdn.cnn.com/cnnnext/dam/assets/190724131447-england-ireland-tease-01-hp-video.jpg" height="144" width="256" />
</media:group>
</item>
所以我在互联网上找到了一些应该注意此类情况的类,例如:SyndicationFeed 或 XDocument.Parse
所以我尝试了这个:
XmlReader reader = XmlReader.Create(urle);
SyndicationFeed feeds = SyndicationFeed.Load(reader); // References -> Right Click -> Add Reference -> System.ServiceModel
reader.Close();
foreach (SyndicationItem item in feeds.Items)
{
string subject = item.Title.Text;
Console.WriteLine("subject: " + subject);
if (item.Summary != null)
{
string summary = item.Summary.Text;
Console.WriteLine("desc: " + summary);
}
}
它与 Title 和 Summary 配合得很好,但它具有处理图像的功能,例如,我如何使用 SyndicationFeed 来做到这一点?