hi,
i neet to get a table content from an html site..
i tried it with this but it didn't give me the information i need.
get-Host $site = Invoke-WebRequest -UseBasicParsing -Uri http://mysite.com $site.Links | Out-GridView
how can i take out the "Lamp Time" and "37 h" out of this source and show it with powershell.. Im still not really into this..(still a noob)
<div align="right"> <br><table width="98%" border="0" cellspacing="2" cellpadding="4"> <tbody> <tr> <th nowrap="" class="item_nm_1">Lamp Time </th> <div align="left">37 h</div><td nowrap="" class="item_op_1"></td> </tr> <tr> <th nowrap="" class="item_nm_1">Total Lamp Hours </th> <td nowrap="" class="item_op_1"> </tr> </tbody></table> <br> </div>
thanks guys,
anita
Article Comments
I've tried but it doesn't seem to work. i get this error.. there is no value defined.
You cannot call a method on a null-valued expression. At C:\Users\user\Desktop\Powershell Scripts\powershell.ps1:23 char:11 + $data = $($site.ParsedHtml.getElementsByTagName("div")) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Cannot index into a null array. At C:\Users\user\Desktop\Powershell Scripts\powershell.ps1:26 char:1 + Write-Host ("{0}:{1}" -f $lamptime[2].Trim(), "Lamp Time") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : NullArray
Jan, 2015 - Permalink
Hi Anita,
from what I can see, you basically only need to get the value as you can set the "Lamp Time" without reading it from the page. You might try with something like the following (not tested, might need adjustment):
Also the code looks kind of ugly. Sorry. :)
An alternative might be:
The above code will work with the HTML snippet from above but not with any other page.
Best regards
Jan, 2015 - Permalink