Miha Žitko
Miha Žitko

Reputation: 83

Powershell get data from webpage

I have a webpage with data from our sun powerplant on webpage http://www.solar-cybro.com/p/alpod-plant/540/.

I am trying to get Output power value to Powershell once every hour with idea to send me email if powerplant doesn't output power during the day.

I tried with Invoke-WebRequest and ParsedHtml.body.getElementsByTagName but didn't get far. I just can't get the number out.

Ideas?

Upvotes: 0

Views: 3172

Answers (1)

Cpt.Whale
Cpt.Whale

Reputation: 5321

For powershell v5, I think your best option is to request the historical timeplot data (basically just hitting the download link on one of the graphs):

$DataNames   = 'c11356.plant_dc_power','c11356.plant_ac_power' -join '+'
$UnitType    = 'day'         
$Units       = 1
$StartDate   = '2021:7:7:15' 
$RequestID   = [long]([double](Get-Date (Get-Date).ToUniversalTime() -UFormat %s)*1000)
$TimeplotURL = "http://www.solar-cybro.com/service/download_timeplot_data/t=$DataNames,p=$UnitType,s=$StartDate,sc=$Units,cum=0,res=24,dec=1,page=540/?rand=$RequestID"

# Get Data
$csv = Invoke-WebRequest -Uri $TimeplotURL -ContentType text/csv | 
    ConvertFrom-Csv -Delimiter ';'

# Optionally save to file
$csv | Export-Csv C:\temp\test.csv

# Display data
$csv

And it nicely outputs the data:

date       time     c11356.plant_dc_power c11356.plant_ac_power
----       ----     --------------------- ---------------------
2021-07-07 08:00:01 906                   887                  
2021-07-07 08:10:01 1002                  983                  
2021-07-07 08:20:01 1084                  1062                 

You'll have to find the specific names/IDs for the data you want, but it should be pretty simple.

Upvotes: 1

Related Questions