Invoke-WebRequest does not display classname

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Bryce McDonald Bryce McDonald 2 weeks, 1 day ago.

  • Author
  • #68757
    Profile photo of random commandline
    random commandline

    I am looking for a specific classname under the element with an id of 'control'. The New-Object method displays the classname, but Invoke-WebRequest does not. Have you encountered sites that do this or am I overlooking something?

    # New-Object Method
    $ie = New-Object -com "InternetExplorer.Application"
    $ie.Visible = $true
    while ($ie.Busy){Start-Sleep 1}
    $doc = $ie.Document
    $control = $doc.getElementById('control')
    $href = $control.childNodes | Where-Object {
        $_.classname -eq 'specific classname'} |
        Select-Object href 
    # Invoke Method
    $test = Invoke-WebRequest -Uri $url 
    $controli = $test.ParsedHtml.getElementById('control') 
    $href = $controli.childNodes  | Where-Object {
        $_.classname -eq 'specific classname'} |
        Select-Object href
  • #68760
    Profile photo of Bryce McDonald
    Bryce McDonald

    With Invoke-Webrequest what we may need to do is first select all elements, then narrow our results. For instance:

    $test = Invoke-WebRequest -Uri $url
    $results = $test.AllElements | Where Class -eq "classname" | Where ID -eq "control" | Select-Object href

    This works in my testing, but it may be a little different in your environment. Let me know!

You must be logged in to reply to this topic.