如何解决无法解析响应内容,因为 Internet Explorer 引擎不可用,或者
在您的调用网络请求中,只需使用参数-UseBasicParsing
例如,在您的脚本(第 2 行)中,您应该使用:
$RSS = Invoke-WebRequest -Uri $url -UseBasicParsing
根据文档,此参数在未安装或配置 IE 的系统上是必需的:
对 HTML 内容使用响应对象,无需文档对象模型 (DOM) 解析。当计算机上未安装 Internet Explorer 时,此参数是必需的,例如在 Windows Server 操作系统的服务器核心安装上。
解决方法
我需要使用 powershell 下载频道 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/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 的首次启动配置不完整。指定
UseBasicParsing 参数并重试。
-
我也试过这个
# --- 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 “$promptr
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 typer
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
错误太多
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。