Powershell 无法分析响应内容,因为Internet Explorer引擎不可用,或者
我需要使用powershell下载channel 9系列,但是我尝试的脚本有错误:Powershell 无法分析响应内容,因为Internet Explorer引擎不可用,或者,powershell,internet-explorer,Powershell,Internet Explorer,我需要使用powershell下载channel 9系列,但是我尝试的脚本有错误: 这个剧本 $url="https://channel9.msdn.com/blogs/OfficeDevPnP/feed/mp4high" $rss=invoke-webrequest -uri $url $destination="D:\Videos\OfficePnP" [xml]$rss.Content|foreach{ $_.SelectNodes("rss/channel/item/enclos
$url="https://channel9.msdn.com/blogs/OfficeDevPnP/feed/mp4high"
$rss=invoke-webrequest -uri $url
$destination="D:\Videos\OfficePnP"
[xml]$rss.Content|foreach{
$_.SelectNodes("rss/channel/item/enclosure")
}|foreach{
"Checking $($_.url.split("/")[-1]), we will skip it if it already exists in $($destination)"
if(!(test-path ($destination + $_.url.split("/")[-1]))){
"Downloading: " + $_.url
start-bitstransfer $_.url $destination
}
}
失败,出现错误:
无法分析响应内容,因为Internet Explorer引擎不可用,或者Internet Explorer的首次启动配置未完成。请指定UseBasicPassing参数,然后重试
# --- settings ---
$feedUrl = "https://channel9.msdn.com/blogs/OfficeDevPnP/feed/mp4high"
$mediaType = "mp4high"
$overwrite = $false
$destinationDirectory = join-path ([Environment]::GetFolderPath("MyDocuments")) "OfficeDevPnP"
# --- locals ---
$webClient = New-Object System.Net.WebClient
# --- functions ---
function PromptForInput ($prompt, $default) {
$selection = read-host "$prompt`r`n(default: $default)"
if ($selection) {$selection} else {$default}
}
function DownloadEntries {
param ([string]$feedUrl)
$feed = [xml]$webClient.DownloadString($feedUrl)
$progress = 0
$pagepercent = 0
$entries = $feed.rss.channel.item.Length
$invalidChars = [System.IO.Path]::GetInvalidFileNameChars()
$feed.rss.channel.item | foreach {
$url = New-Object System.Uri($_.enclosure.url)
$name = $_.title
$extension = [System.IO.Path]::GetExtension($url.Segments[-1])
$fileName = $name + $extension
$invalidchars | foreach { $filename = $filename.Replace($_, ' ') }
$saveFileName = join-path $destinationDirectory $fileName
$tempFilename = $saveFilename + ".tmp"
$filename
if ((-not $overwrite) -and (Test-Path -path $saveFileName))
{
write-progress -activity "$fileName already downloaded" -status "$pagepercent% ($progress / $entries) complete" -percentcomplete $pagepercent
}
else
{
write-progress -activity "Downloading $fileName" -status "$pagepercent% ($progress / $entries) complete" -percentcomplete $pagepercent
$webClient.DownloadFile($url, $tempFilename)
rename-item $tempFilename $saveFileName
}
$pagepercent = [Math]::floor((++$progress)/$entries*100)
}
}
# --- do the actual work ---
[string]$feedUrl = PromptForInput "Enter feed URL" $feedUrl
[string]$mediaType = PromptForInput "Enter media type`r`n(options:Wmv,WmvHigh,mp4,mp4high,zune,mp3)" $mediaType
$feedUrl += $mediaType
[string]$destinationDirectory = PromptForInput "Enter destination directory" $destinationDirectory
# if dest dir doesn't exist, create it
if (!(Test-Path -path $destinationDirectory)) { New-Item $destinationDirectory -type directory }
DownloadEntries $feedUrl
错误太多
在调用web请求中,只需使用参数
-UseBasicParsing
e、 g.在脚本(第2行)中,您应该使用:
$rss = Invoke-WebRequest -Uri $url -UseBasicParsing
$rss = Invoke-WebRequest -UseBasicParsing
根据,此参数在未安装或配置IE的系统上是必需的:
对HTML内容使用响应对象,而不进行文档对象模型(DOM)分析。如果计算机上未安装Internet Explorer,例如Windows Server操作系统的服务器核心安装,则需要此参数
要使其在不修改脚本的情况下工作,请执行以下操作: 我在这里找到了一个解决方案: 这个错误很可能是因为IE还没有第一次启动,于是出现了下面的窗口。启动它并通过该屏幕,然后错误消息将不再出现。不需要修改任何脚本
这是肯定的,因为Invoke WebRequest命令依赖于Internet Explorer程序集,并且根据默认行为调用它来解析结果。正如Matt所建议的,您只需启动IE并在第一次启动时弹出的设置提示中进行选择。你所经历的错误将会消失 但是,只有当您以启动IE的windows用户的身份运行powershell脚本时,这才是可能的。IE设置存储在当前windows配置文件下。因此,如果像我一样,以系统用户的身份在服务器上的调度程序中运行任务,这将不起作用
因此,您必须在这里更改脚本并添加-UseBasicParsing参数,如本例所示:
$WebResponse=Invoke WebRequest-Uri$url-TimeoutSec 1800-ErrorAction:Stop-Method:Post-Headers$Headers-UseBasicParsing
您可以通过运行此PowerShell脚本禁用运行Internet Explorer首次启动配置的需要,它将调整相应的注册表属性:
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Internet Explorer\Main" -Name "DisableFirstRunCustomize" -Value 2
在这之后,WebClient将毫无问题地工作我也遇到了这个问题,而-UseBasicPassing将对一些人起作用,如果您确实需要与dom交互,它将不起作用。尝试使用a组策略阻止初始配置窗口出现,powershell将不再阻止您。 看这里
找到此页面后,我只花了几分钟时间,一旦设置了GP,powershell将允许您通过。另一种解决方法:更新注册表。在我的情况下,我无法更改GPO,并且-UseBasicPassing会中断对网站的部分访问。另外,我有一个没有登录权限的服务用户,因此我无法作为该用户登录并运行GUI。
要解决
在调用web请求的文件中,只需使用参数-UseBasicParsing e、 g.在脚本(第2行)中,您应该使用:
$rss = Invoke-WebRequest -Uri $url -UseBasicParsing
$rss = Invoke-WebRequest -UseBasicParsing
根据文档,此参数在未安装或配置IE的系统上是必需的
对HTML内容使用响应对象,而不进行文档对象模型(DOM)分析。如果Internet Explorer未安装在计算机上,例如Windows Server操作系统的服务器核心安装上,则需要此参数。问题的答案在错误消息中(使用UseBasicParsing参数)。公平地说,很容易看到“Internet Explorer”字样在错误消息中,忽略消息的其余部分,因为您对命令行实用程序依赖IE的原因大发雷霆。为我工作时,无需将Server 2008 Server到Server 2012 R2的所有脚本更新为一系列使用PowerShell的自动化进程。这使用了一个特定的帐户,因此我确实必须在该帐户登录到服务器的情况下运行它。虽然这确实消除了错误,但考虑到PowerShell将用作自动化平台,通过GUI解决问题的需要并不是一个可接受的答案。此答案不适用于所有场景,例如,在PowerShell远程处理会话中。:计算机配置>策略>管理模板>Windows组件>Internet Explorer。设置“防止运行首次运行向导”“启用并选择适合您的选项的策略。我在kubectly代理上遇到了这个问题,在使用curl时已经解决了这个问题。谢谢如果您的应用程序位于某种自动缩放组中,则此场景也将不起作用,因为正在旋转的新实例将需要此每日/每周/等。对于对
UseBasicParsing
正在执行的操作感兴趣的未来访问者,最好使用-UseBasicParsing:使用响应对象处理HTML内容,而不使用文档对象模型(DOM)解析。如果计算机上未安装Internet Explorer,例如Windows Server操作系统的服务器核心安装,则需要此参数。
从此处复制:我已在此服务器上安装了Internet Explorer,并且已安装。而且它仍然需要-使用BasicPassing。不知道为什么。不幸的是,这只适用于GUI版本,而不适用于Windows Server Core。@Luke好的,我将尝试找到适用于Windows Server Core的解决方案