New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


get table content from html site with powershell

Votes:

0

Your Vote:

Up

Down

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

content html maps powershell prtg snmp table

Created on Jan 21, 2015 3:29:34 PM by  dika (0) 1

Last change on Jan 21, 2015 6:27:07 PM by  Konstantin Wolff [Paessler Support]



3 Replies

Votes:

0

Your Vote:

Up

Down

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):

$site = Invoke-WebRequest -UseBasicParsing -Uri http://mysite.com  
$data = $($site.ParsedHtml.getElementsByTagName("div"))
$lamptime = $data[0].innerText.Split(" ")
Write-Host ("{0}:{1} {2}" -f $lamptime[2].Trim(), $lamptime[0].Trim(), $lamptime[1].Trim())

Also the code looks kind of ugly. Sorry. :)
An alternative might be:

$site = Invoke-WebRequest -UseBasicParsing -Uri http://mysite.com  
$data = $($site.ParsedHtml.getElementsByTagName("div"))
$lamptime = $data[0].innerText.Split(" ")
Write-Host ("{0}:{1}" -f $lamptime[2].Trim(), "Lamp Time"

The above code will work with the HTML snippet from above but not with any other page.
Best regards

Created on Jan 22, 2015 12:54:10 PM by  Konstantin Wolff [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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
 

Created on Jan 23, 2015 8:58:52 AM by  dika (0) 1

Last change on Nov 9, 2015 12:32:35 PM by  Luciano Lingnau [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Can you provide me with the HTML file you're trying to check?

Created on Jan 26, 2015 1:55:58 PM by  Stephan Linke [Paessler Support]



Please log in or register to enter your reply.


Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.