2016-07-09 3 views
0

Я пытаюсь написать сценарий PowerShell, чтобы открыть окно в хроме, перейти в Google, ввести текст в строке поиска, нажать enter и затем получить все ссылки в массиве. Вот моя первая попытка на код:Сценарий для открытия веб-страницы и поиска

$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

На реальном сайте, вам нужно сделать получить или должность ? –

ответ

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