I'm trying to build a new object with properties from this webpage:
http://us.battle.net/sc2/en/game/unit/
(Heart of the Swarm)
Ultimately I would like something like the following for every unit:
unit strong-against weak-against cost time
-------- ---------------------- ------------------------- ------- ----
colossus marine,zergling,zealot viking,corruptor,immortal 300,200 75
I could maybe even add more properties once I get the basic idea. This code is what I have so far, but it seems that I have an array within the noteproperty "onclick" that I'm having a problem with. I'm unsure how to add each individual unit as a property (and not an array for one property).
#get main page
$url_main = 'http://us.battle.net/sc2/en/game/unit/'
If (!$main) {$main = Invoke-WebRequest $url_main}
#create new object with list of units
$units = $main.AllElements `
| Where-Object -Property class -Match "button\-rollover" `
| Select-Object -Property "onclick"
#clean up array
foreach ($unit in $units) {
$unit = $unit -replace "@{onclick=Core.goTo\(\'" , ""
$unit = $unit -replace "\'\)}" , ""
$unit
}
thanks,
Ken
Update: This seems to be closer to what I'm looking for, but still not able to put it all into the above format.
#get main page
$url = 'http://us.battle.net/sc2/en/game/unit/'
If (!$result) {$result = Invoke-WebRequest $url}
#create new object with list of units
$result.AllElements `
| Where-Object -Property class -Match "button\-rollover" `
| Select-Object -ExpandProperty innerText
#unit,mineral,vespene,supply,buildtime,producer,life,shields,energy,armor