Downloading Information from Internet (Part 2)

by Apr 16, 2018

Invoke-WebRequest can download any type of information, and it is up to you to convert it into the format of choice. In the previous tip, we illustrated how to deal with JSON data. Now let’s take a look at webpages that deliver XML data:

This example retrieves current currency exchange rates from the European Central Bank:

$url = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
$result = Invoke-WebRequest -Uri $url -UseBasicParsing
$result.Content

Here is the result:

$url = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'
$result = Invoke-WebRequest -Uri $url -UseBasicParsing
$xml = [xml]$result.Content
$xml.Envelope.Cube.Cube.Cube

Twitter This Tip! ReTweet this Tip!