我运行了该powershell脚本,以从网站下载图像(要下载图像,必须执行某些步骤,这就是我使用IE导航的原因)。我放置了一个随机字符串,其间隔为4到4个字符。

但是我得到一个错误,它甚至没有开始用字符串填充空白:

Exception from HRESULT: 0x800A01B6
At E:\getbd.ps1:13 char:1
+ $ie.Document.getElementsByTagName("text") | where { $.name -eq "words ...

Here is the code:

$url = "https://fakecaptcha.com"
$set = "abcdefghijklmnopqrstuvwxyz0123456789".ToCharArray()
for($i=1; $i -le 4; $i++){
$result += $set | Get-Random}
$result += ' '
for($i=1; $i -le 4; $i++){
$result += $set | Get-Random}
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent = $true
$ie.Navigate( $url )
while( $ie.busy){Start-Sleep 1}
$ie.Document.getElementsByTagName("text") | where { $.name -eq "words" }.value = $result
$generateBtn = $ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'submit' -and $_.Value -eq 'Create it now!'}
$generateBtn.click()
while( $ie.busy){Start-Sleep 1}
$readyBtn = $ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'button' -and $_.Value -eq 'Your captcha is done! Please click here to view it!!'}
$readyBtn.click()
while( $wc.busy){Start-Sleep 1}
$downloadBtn = $ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'button' -and $_.Value -eq 'DOWNLOAD'}
$downloadBtn.click()
while( $ie.busy){Start-Sleep 1}
$source = $ie.document.getElementsByTagName('img') | Select-Object -ExpandProperty src
$file = '$E:\bdlic\'+$result+'.jpg'
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($source,$file)
while( $wc.busy){Start-Sleep 1}
$ie.quit()

最佳答案

您在该行中有2个语法错误:

$ie.Document.getElementsByTagName("text") | where { $.name -eq "words" }.value = $result
#                                                   ^                   ^^^^^^
  • $.Name:“当前对象”变量是$_,而不仅仅是$
  • where {...}.value:不能在Where-Object语句的脚本块上使用点符号。为此,您需要将整个语句放在一个(sub)表达式中。

  • 将行更改为此:
    ($ie.Document.getElementsByTagName("text") | where { $_.name -eq "words" }).value = $result
    

    关于powershell - 从网站下载图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35819709/

    10-13 07:20