Powershell Tip : Parsing HTML from a local File or a String

INTRODUCTION :If you are familiar with Invoke-WebRequest cmdlet then you must be aware that you get a parsed HTML from the requested Web URL. DOMstructure of this Parsed HTML could be utilized to get access to HTML elements of the web page, like in the below animation –PROBLEM :W

 
 
 
 
 
5 Star
(12)
4,541 times
Add to favorites
3/31/2017
E-mail Twitter del.icio.us Digg Facebook
  • not working on Windows server OS
    3 Posts | Last post February 11, 2018
    • this method doesn't work on Windows server OS (tried 2012, 2012 R2 and 2016). the IHTMLDocument2_write method does not exist on server. Suggest just parse the HTML as XML , it's pretty simple: [xml]$html=get-content c:\yourhtml.html
    • Hello Tao, The method worked with me when tested using invoke-restmethod instead of using the invoke-webrequest 
      I tested on Windows Server 2012 R2 and Windows Server 2016
    • As Tao Yang noted on server, the same applies to the LTSB versions of Windows 10.
  • Just use Invoke-Webrequest
    2 Posts | Last post February 07, 2018
    • You could just use Invoke-Webrequest if you pass the fully qualified path to -Uri:
      
      Invoke-Webrequest -Url 'C:\full\path\to\some\file.html'
      
      Tested on PowerShell 5.1 and 5.0
    • Oh, I see that the post is about getting the ParsedHtml property.. Never mind :)