2016-06-24 22 views
1

私はPowerShellを使用してWebページに移動しています。私はすべてのdiv要素をループしています:PowerShell - Webページ上のdivをループしてIDを印刷します。

$ie = New-Object -com InternetExplorer.Application 

$ie.visible=$true 

$ie.navigate("URL") 

$divs = $ie.document.getElementsByTagName("div") 
Foreach($div in $divs) 
{ 
    $div 
} 

これは、「システム.__ ComObjects」としてdivを識別します。 Get-Memberは(...私はIE11を使用していますが)有望な音 "ie9_getAttribute" のようなメソッドを返しますが、 "$ div.ie9_getAttribute(" ID ")" スロー:最初のdivのため

Exception calling "ie9_getAttribute" with "1" argument(s): "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" 

をおよび:

Method invocation failed because [System.__ComObject] doesn't contain a method named 'ie9_getAttribute'. 

(後続のdivの場合)私は、 "システム.__ ComObject" からIDを抽出することができますどのように

Here is the HTML I am parsing.

答えて

0

あなたは単にあなたが$divs内のオブジェクトを反復しているとして、各オブジェクトの.idプロパティを取得する必要があります。

Foreach($div in $divs) 
{ 
    $div.id 
} 
関連する問題