1

I have this script:

$URI = "http://www.trlibor.org/fixingrates.asp"
$HTML = Invoke-WebRequest -Uri $URI

$1MRate = $HTML.ParsedHtml.getElementsByTagName("td")[11].InnerText
$1MRate = $1MRate.replace(',','.')
$1MRate

$2MRate = $HTML.ParsedHtml.getElementsByTagName("td")[15].InnerText
$2MRate= $2MRate.replace(',','.')
$2MRate

$3MRate = $HTML.ParsedHtml.getElementsByTagName("td")[19].InnerText
$3MRate= $3MRate.replace(',','.')
$3MRate


$6MRate = $HTML.ParsedHtml.getElementsByTagName("td")[23].InnerText
$6MRate= $6MRate.replace(',','.')
$6MRate

$9MRate = $HTML.ParsedHtml.getElementsByTagName("td")[27].InnerText
$9MRate= $9MRate.replace(',','.')
$9MRate

$1YRate = $HTML.ParsedHtml.getElementsByTagName("td")[31].InnerText
$1YRate= $1YRate.replace(',','.')
$1YRate

It's working TOTALLY fine on my machine, but when I run it on a Windows Server R12, the variables $1MRate...$2MRate are not getting values (null) as if the td elements do not exist on that page.

any idea why is that?

6
  • Access problems? check what is in $HTML ("This site can’t be reached"?) Commented Jul 12, 2017 at 8:05
  • I can reach it fine on my local machine, I can browse it fine on Server manually in IE. Commented Jul 12, 2017 at 8:08
  • I notice that on my local machine PS is 5 while on server it's 4 Commented Jul 12, 2017 at 8:09
  • On the server side try Write-Host $HTML.content to confirm that this is what you expect (= the same on your local machine). Commented Jul 12, 2017 at 8:16
  • It turns out that the array [11] ...... don't work on PS4, is there another method to select the 11th td element other than [11]? Commented Jul 12, 2017 at 8:27

2 Answers 2

1

IT TURNED OUT that $1MRate = $HTML.ParsedHtml.getElementsByTagName("td")[11].InnerText returns null in PS4!!

You have to use $1MRate = $HTML.ParsedHtml.getElementsByTagName("td").item(11).InnerTex instead!!

Sign up to request clarification or add additional context in comments.

Comments

0

Try:

$HTML = Invoke-WebRequest -Uri $URI -ContentType "text/html; charset=utf-8"

When upgrading from PowerShell 3 to 4, my Invoke-WebRequest broke and required ContentType to be explicitly stated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.