The provided image gives you the core of the method, but I will elaborate further for the “Uninitiated”.
Many websites publish their content, or a subset thereof, as RSS feeds. RSS means “Really Simple Syndication” and is a structured methodology for offering news and articles in a format which standardized for access and interpretation by multiple viewers and viewing platforms.
This is not to say that the full content of most news sites is available via this method, however. Far from it. In fact many news sources limit the number of characters, lines, or even which articles are contained within the Feed.
Many news sources made the above shift (to limited Feed content) as a result of “content theft” (as they saw it) but other websites who were, in many cases, accused of wholesale copying of content from source sites.
But, enough about that. Today we will cover how you can use PowerShell to read the headlines and content from Reddit’s World News Subreddit, starting with the “Invoke-Restmethod” commandlet.
Invoke-RestMethod [-Method ] [-FollowRelLink] [-MaximumFollowRelLink ] [-ResponseHeadersVariable ] [-StatusCodeVariable ] [-UseBasicParsing] [-Uri] [-WebSession ] [-SessionVariable ] [-AllowUnencryptedAuthentication] [-Authentication ] [-Credential ] [-UseDefaultCredentials] [-CertificateThumbprint ] [-Certificate ] [-SkipCertificateCheck] [-SslProtocol ] [-Token ] [-UserAgent ] [-DisableKeepAlive] [-TimeoutSec ] [-Headers ] [-MaximumRedirection ] [-MaximumRetryCount ] [-RetryIntervalSec ] [-Proxy ] [-ProxyCredential ] [-ProxyUseDefaultCredentials] [-Body
This utility has a lot of options, but for today we will keep it simple with “$z = invoke-restmethod https://www.reddit.com/r/worldnews/.rss”.
The first part “$z = ” captures whatever follows it as a variable or (as I think of it) a pseudo-object which can later be reused much more easily than retyping the entire command and without repeated calls to the target server (a “great” way to get IP banned).
The second part is the commandlet itself, while the third represents the path to the RSS feed we will pull data from.
Once you have the data you can display the basics from it by simply typing “$z” and pressing enter. You should see something similar to the following:
I am sure the visionaries among you already see the benefits of this method, and are already mentally Designing new ways to view the news – but don’t go yet. Let’s unpack these results first.
By invoking “$z” we only display/unpack the first result in the result set. let’s go deeper.
By running $z.title we get only the title text, without all the other fluff. Now let’s list only the titles for all articles.
The above gets us the titles, but looks like a jumble snd may be difficult to read for many. Let’s make it prettier.
Much better. Each title on its own line with a sequence number assigned. From here one could export the data to CSV, to XML, or even to push the data to a separate server for archiving, display, or delivery.
This is a simplistic example, intended to provide those who are ready with a basic PowerShell skill, which may empower you to create your next software and/or scripting masterpiece.
Now, go use your newfound powers for Good instead of Evil. ✋🏾