Search Internet Explorer Object

This topic contains 1 reply, has 2 voices, and was last updated by  Dave Wyatt 3 years, 4 months ago.

  • Author
    Posts
  • #14277

    Seth Burton
    Participant

    I am new to powershell, and am trying to write a script that opens Internet Explorer, navigates to a page, then searches that page for a string of text. Here is the beginning of my code, I just can't seem to figure out how to search the hidden page once it opens for a string of text, such as "EXAMPLE"

    $ie = New-Object -com InternetExplorer.Application
    $ie.visible=$false
    $ie.navigate("www.example.com")
    while($ie.ReadyState -ne 4) {start-sleep -m 100}

    Any help would be greatly appreciated.

  • #14279

    Dave Wyatt
    Moderator

    Are you fixed on using Internet Explorer for this? You'd have an easier time using Invoke-WebRequest, in PowerShell. For example:

    $response = Invoke-WebRequest -Uri 'http://www.example.com'
    

    $response will be a [Microsoft.PowerShell.Commands.HtmlWebResponseObject] object which has lots of useful properties. $response.Content will give you the page's raw HTML code. The AllElements, Forms, Headers, Images, InputFields and Links properties give you access to information about the HTML tags found on the page.

    $response.ParsedHtml will be a reference to a COM object that lets you access the HTML DOM model directly (though I'll warn you, this is very slow in PowerShell for some reason. Use the other properties if they'll get the job done for you.) For instance, you could execute $response.ParsedHtml.documentElement.getElementsByTagName('table')

You must be logged in to reply to this topic.