X

Learn to use PowerShell to extract data from RSS

powershell

Currently I am doing some performance testing on our application and part of it is seeing how well do we handle “insert” in our application. (Are there any problems etc, how many can it handle, etc)
I am using JMeter to test the performance and it is quite a flexible product that I will talk about later in one of the blog post on using JMeter to perf test ASP .NET application.

So back to PowerShell. Basically I needed a good source of data to (e.g real live data) that people type, so what came to my mind was, why don’t I just use some RSS data out there and try it out, it gives good and real information rather than generic data like “Hello World” that I may generate.

So I took upon to use the CBC News for Ottawa as an RSS feed, local news good data and it changes everyday and every 15 minutes or so.
Please note don’t hit the server continuously to try the script out, I don’t want CBC to be made at me 🙂

So here is a simple script.

$rssUrl = "http://rss.cbc.ca/lineup/canada-ottawa.xml"
$blog = [xml](new-object System.Net.WebClient).DownloadString($rssUrl)
$items = $blog.rss.channel.item

foreach($row in $items)
{	
	$row.title + "|" + $row.description.Replace("`n",'') + "|" + $row.link
}

So this will output data on the screen with
e.g This news is awesome|Reports have reported that this news is awesome|http://www.someurl.com

The reason I choose “|” rather than csv(comma separated) is because there could be data in there that could have comma in them.

Also in order to output it to a file one has type into PowerShell prompt
$ CBCRssPopulate.ps1 | out-file “cbcnews.txt” -encoding ascii

Please note the ascii setting at the end since by default everything in PowerShell is unicode and you might get into issues later on for parsing data.

Recommended Tool for PowerShell editing is PowerGUI http://www.powergui.org/index.jspa

Have fun 🙂

Categories: Misc
Tags: PowerShell
Taswar Bhatti:
Related Post