我正在尝试编写PowerShell脚本以打开chrome中的窗口,转到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 }