转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

环境:Windows Server 2012 EN(解决PowerShell控制台中文乱码问题:方法

通过PowerShell处理RSS信息,直接通过Invoke-Webrequest命令获取到的内容中文乱码,原因是没有指定Encoding模式,而Invoke-Webrequest命令目前并不支持指定Encoding,所以只能把获取到的网页($url)内容保存到本地($filePath),然后从本地进行读取(根据不同方式可以选择性指定Encoding)。拿博客园的RSS页面为例,获取页面中最新博客的标题("title")。代码如下:

$url = "http://feed.cnblogs.com/blog/u/212109/rss"
$filePath = "C:\Users\pkmacct\Desktop\test.txt"
$nodeName = "title"
Invoke-WebRequest -Uri $url -OutFile $filePath
$xmlDoc = New-Object "System.Xml.XmlDocument"  
$xmlDoc.Load($filePath)  
$xmlDoc.GetElementsByTagName($nodeName)|select '#text'

调用脚本运行结果如下:

PowerShell处理RSS信息

相关文章:

  • 2021-05-28
  • 2021-04-14
  • 2021-12-02
  • 2021-11-04
  • 2021-11-05
  • 2021-12-23
  • 2021-11-18
猜你喜欢
  • 2018-01-30
  • 2021-08-28
  • 2021-11-06
  • 2020-11-14
  • 2021-07-12
  • 2021-09-22
  • 2020-02-19
  • 2021-11-01
相关资源
相似解决方案