我使用此功能下载一些RSS提要,并将其写入Excel文件中:
Function Get-RSS {
param ([string]$url)
$Results = @()
$wc = New-Object Net.WebClient
$wc.Encoding = [System.Text.Encoding]::UTF8
[xml]$resp = $wc.DownloadString("$url")
$article = $resp.rss.channel.item
foreach ($in in $article) {
[string]$description = $in.description.InnerText -replace "<.*?>"
$Results += Set-News -Title $in.title -Content $description -PublishDate $in.pubDate -Link $in.OrigLink
}
return $Results
}
下载工作正常,但我对像这样的特定字符有疑问:
我在Excel中看到了,如何将其转换为该代码后面的char?
最佳答案
您需要解码html字符。更改
[xml]$resp = $wc.DownloadString("$url")
至
[xml]$resp = [System.Web.HttpUtility]::HtmlDecode($wc.DownloadString("$url"))
如果您使用的是PS2,则在脚本/函数顶部添加
Add-Type -AssemblyName System.Web
以导入所需的.NET二进制文件。关于powershell - Powershell:如何将 “ISO” char转换为UTF8?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24387095/