0

次の powershell スクリプトを実装することは可能ですか?

目的は、後でスクリプト ブロックを呼び出して、html コントロールを取得することです。

$sites = @{
    site1= @{ 
        url = "......."; 
        inputUserID = { $doc.getElementsByID("username"]) }; #Some code to get the html input control
        inputPassword = { $doc.getElementsByName("passowrd"]) }; #Some code to get the html input control
    };
    .....
}

$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.navigate($sites[$site]["url"])
$ie.visible = $true
while ($ie.busy) { start-sleep -milliseconds 1000; }

... #Get the input controls and fill the values

質問が更新されました。それは十分に明確ですか?理解するのはそれほど難しいことではないはずです。

4

2 に答える 2

0

各サイトの情報を反復処理する必要があります。IE COM オブジェクトで DOM セレクターをどのように使用しているかわからないので、コードのその部分を推測しました。

$sites = @{
    site1= @{ 
        url = "......."; 
        inputUserID = ( 'doc.getElementsByID("username")' ); #Some code to get the html input control
        inputPassword = ( 'doc.getElementsByName("passowrd")' ); #Some code to get the html input control
    };
    .....
}

$sites.Keys | 
    ForEach-Object {
        $siteInfo = $sites[$_]
        $ie = New-Object -ComObject "InternetExplorer.Application"
        $ie.navigate($siteInfo.url)
        $ie.visible = $true
        while ($ie.busy) { start-sleep -milliseconds 1000; }
        ... #Get the input controls and fill the values
        $usernameElement = $ie.someFunction( $siteInfo.inputUserID )
        $passwordElement = $ie.someFunction( $siteInfo.inputPassword )
    }
于 2012-07-11T00:36:21.267 に答える
0

PowerShell でスクリプト ブロックからクロージャーを取得する方法は次のとおりです。

{  #code here  }.GetNewClosure()

上記のコードから、これが役立つかどうかを判断するのは困難ですが、それはあなたが求めたものです。

于 2012-07-10T01:12:37.840 に答える