2016-07-09 9 views
0

私はChromeでウィンドウを開き、googleに移動し、検索バーにテキストを入力してEnterキーを押し、配列内のすべてのリンクを取得するPowerShellスクリプトを作成しようとしています。ここでは、コードでの私の最初の試みです:スクリプトを使用してWebページと検索を開く

$URI = "www.google.com" 
$HTML = Invoke-WebRequest -Uri $URI 
$SearchField = $HTML.ParsedHtml.getElementById('lst-ib') 
$SearchField.value = "green flowers" 
$SearchButton = $HTML.ParsedHtml.getElementsByName('btnK') 
$SearchButton.click(); 
//Grab links and store into array 

は、しかし、私はそれを実行しようとすると、私はこれを取得:本物のサイトで

The property 'value' cannot be found on this object. Verify that the property 
exists and can be set. 
At line:4 char:1 
+ $SearchField.value = "green flowers" 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [], RuntimeException 
    + FullyQualifiedErrorId : PropertyAssignmentException 

Method invocation failed because [System.DBNull] does not contain a method named 
'click'. 
At line:6 char:1 
+ $SearchButton.click(); 
+ ~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidOperation: (:) [], RuntimeException 
    + FullyQualifiedErrorId : MethodNotFound
+0

を、あなたは、GETまたはPOSTを実行する必要があります? –

答えて

0
$Site = "www.google.com/search?q=green+flowers" 
$Test = Invoke-WebRequest -URI $Site 
$Test.Links | Foreach {$_.href } 
関連する問題