Skip to content Skip to sidebar Skip to footer

In Powershell, Is There A Way To Convert Html To A Object With Depth?

I was working with Powershell to experiment with webscraping and wondered if there was an easier way to deal with elements? Is there a way to convert an Html page to an object in p

Solution 1:

Yes, $page.ParsedHtml gives you the object structure.

As a tip for you to learn how to discover such functionality in PowerShell: Pipe your objects to Get-Member to see all available properties/methods, etc. And to quickly see what all the properties are, you can pipe it to select *

Solution 2:

You are likely looking for getElementsByTagName

$ret = invoke-webrequest -uri [uri]

$ret.parsedhtml.getelementsbytagname('table')[0] 

gets you the first table in your html document

$ret.parsedhtml.getelementsbytagname('tr')[0]

gets you the first <tr> row in your HTML document.

Post a Comment for "In Powershell, Is There A Way To Convert Html To A Object With Depth?"