Created
April 29, 2024 01:31
-
-
Save judismith/77fae4bcb686d61ad4c5603aa150be3b to your computer and use it in GitHub Desktop.
Parse RSS Feed from Wordpress Blog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ServiceModel.Syndication; | |
using System.Xml; | |
using System.Xml.Linq; | |
string url = "https://shaolinarts.com/feed/rss/"; | |
XmlReader reader = XmlReader.Create(url); | |
SyndicationFeed feed = SyndicationFeed.Load(reader); | |
reader.Close(); | |
foreach (SyndicationItem item in feed.Items) | |
{ | |
var author = ""; | |
foreach (SyndicationElementExtension extension in item.ElementExtensions) | |
{ | |
XElement ele = extension.GetObject<XElement>(); | |
if (ele.ToString().StartsWith("<dc:creator")) | |
{ | |
var start = ele.ToString().IndexOf(">") + 1; | |
var end = ele.ToString().IndexOf("</dc:creator>"); | |
author = ele.ToString().Substring(start, end - start); | |
} | |
} | |
Console.WriteLine(); | |
Console.WriteLine(); | |
var description = item.Summary.Text; | |
var first = description.IndexOf("src=\"") + "src=\"".Length; | |
var last = description.IndexOf("jpg\"", first); | |
var imgLink = description.Substring(first, last - first + 3); | |
var text = description.Substring(description.IndexOf("<p>") + 3, description.IndexOf("</p>") - description.IndexOf("<p>") - 3); | |
Console.WriteLine(item.PublishDate); | |
Console.WriteLine(item.Title.Text); | |
Console.WriteLine(author); | |
Console.WriteLine(); | |
Console.WriteLine(imgLink); | |
Console.WriteLine(text); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Parse an RSS feed from a WordPress blog using C# and .Net Core 8. Show the technique for getting the standard individual items in SyndicationItem. The solution also shows how to get the additional elements using SyndicationElementExtension.