Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell进行Web抓取-空href_Powershell_Web Scraping - Fatal编程技术网

使用PowerShell进行Web抓取-空href

使用PowerShell进行Web抓取-空href,powershell,web-scraping,Powershell,Web Scraping,我正在尝试从网页上获取下载链接,但在某些网页中,有些是 具有“单击此处重试”内部文本的链接,看起来像 在任何web浏览器中,但不在PowerShell中 什么不起作用 我尝试调用WebRequest: PS> $url="https://www.google.com/chrome/browser/thankyou.html?standalone=1&system=true&platform=win" PS> (Invoke-WebRequest $url).Li

我正在尝试从网页上获取下载链接,但在某些网页中,有些是

具有“单击此处重试”内部文本的链接,看起来像

在任何web浏览器中,但不在PowerShell中

什么不起作用 我尝试调用WebRequest

PS> $url="https://www.google.com/chrome/browser/thankyou.html?standalone=1&system=true&platform=win"  
PS> (Invoke-WebRequest $url).Links | ? {$_.InnerText -eq "click here to retry"} | select outerHTML, href | fl

outerHTML : <A class=retry-link href="#" data-g-label="retry-dl"
            data-g-event="retry-download">click here to retry</A>
href      : #
还有别的选择吗?
如果您知道如何在不使用IE的情况下从此类链接中获取适当的
href
值,请告诉我。

有两种方法可以获得您想要的。让浏览器运行javascript,或者自己查找并解析脚本文件以提取URL。@Ryan Bemrose>或者自己查找并解析脚本文件以提取URL。我该怎么做?编写我自己的通用javascript解析器?(你不是认真的吧?)
$url="https://www.google.com/chrome/browser/thankyou.html?standalone=1&system=true&platform=win"

$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true

$ie.Navigate2($url)
while ($ie.busy)                               { Start-Sleep -m 100 }
while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }

$link = $ie.Document.getElementsByTagName("a") | ? { $_.InnerText -eq "click here to retry" } | select -First 1 -expandProperty href
Write-Host $link