Parse and manipulate HTML Files

Welcome Forums General PowerShell Q&A Parse and manipulate HTML Files

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 6 months ago.

  • Author
  • #76388

    Points: 1
    Rank: Member

    What is the best way to load html files from a file system, parse it, manipulate the DOM then save it back to a file?

    I am trying following code but is does not seem to work because the type is Microsoft.PowerShell.Commands.WebResponseObject and not the Microsoft.PowerShell.Commands.HtmlWebResponseObject which provides for the $html.ParsedHtml property.

    $uri = "C:\temp\EventLog.html"
    $html = Invoke-WebRequest -Uri $uri
    $html | Get-Member

  • #76411

    Points: 64
    Rank: Member

    I could be wrong but I don't think that Invoke-Webrequest will have access to the dom. you may have to use

    $ie = new-object -ComObject "InternetExplorer.Application"
    $uri = "C:\temp\EventLog.html"
    $result = $ie.document.body # depending on what you wanted to get to.

    and don't forget to kill the ii session when you have finished.

The topic ‘Parse and manipulate HTML Files’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort