Powershell Web Page Automation works on Internet, not Intranet

后端 未结 3 1023
甜味超标
甜味超标 2020-12-17 06:40

I\'m trying to do some simple automation with Powershell, pulling link URLs from one of our company\'s local intranet pages, and then doing some work with those URLs. Eventu

相关标签:
3条回答
  • 2020-12-17 07:22

    Maybe the solution is here: http://blogs.msdn.com/b/ieinternals/archive/2011/08/03/internet-explorer-automation-protected-mode-lcie-default-integrity-level-medium.aspx

    It explained the different levels of tabs, in ie. You have to use the "medium tab" to navigate in local zone.

    Basically, the best way to keep your ie settings and use your script is to create a registry key, as explained in the link above.

    Windows Registry Editor Version 5.00
    
    [HKEY_CLASSES_ROOT\InternetExplorer.ApplicationMedium]
    
    [HKEY_CLASSES_ROOT\InternetExplorer.ApplicationMedium\CLSID] 
    @="{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}"
    

    And in your script, use this new com object:

    $ie = new-object -Com InternetExplorer.ApplicationMedium
    ...
    
    0 讨论(0)
  • 2020-12-17 07:26

    Use

    $ie.Document.documentElement.getElementsByClassName("underline")
    

    and enjoy .....

    0 讨论(0)
  • 2020-12-17 07:33

    Due to policy restrictions on my computer, I was not able to access the registry to create the key mentioned in another answer. However, I did find a way to do it indirectly using PowerShell in case this is helpful to anyone else:

    $type = [Type]::GetTypeFromCLSID('D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E')
    $ie = [System.Activator]::CreateInstance($Type)
    
    $ie.Visible = $true
    
    $URL = "http://my.intranet.com"
    
    $ie.Navigate($URL)
    
    Write-Host "`$ie.Busy:" $ie.Busy
    Write-Host "`$ie.ReadyState:" $ie.ReadyState
    
    while($ie.Busy -or ($ie.ReadyState -ne 4) ) {
        Start-Sleep -s 1
    }
    
    Write-Host "IE is ready"
    
    0 讨论(0)
提交回复
热议问题