Quantcast
Channel: Parse a website and turn html content into variables within PowerShell - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Parse a website and turn html content into variables within PowerShell

$
0
0

How would I call a URL and turn the page content into variables to use in PowerShell?

The HTML page looks like this:

<!DOCTYPE html><html><head></head><body><span class="server1var1">8</span><span class="server1var2">2</span><span class="server2var1">5</span><span class="server2var2">1</span></body></html>

Then in PowerShell I want these variables:

$server1var1 = "8"$server1var2 = "2"$server2var1 = "5"$server2var2 = "1"

Accepting the answer below with one modification to make it work for me. Changing $_.textContent to $_.innerhtml solved the issue.

$content = Invoke-WebRequest -Uri 'http://urltomysite'$content.ParsedHtml.getElementsByTagName('span') | ForEach-Object {     New-Variable -Name $_.className -Value $_.innerhtml    }

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>