powershell解析cdata-section

use*_*524 4 rss powershell cdata

我正在尝试使用powershell读取rss feed,但我无法在feed中提取cdata-section

这是一个Feed的片段(为了节省空间而剪切了一些项目):

<item rdf:about="http://philadelphia.craigslist.org/ctd/blahblah.html">
<title>
<![CDATA[2006 BMW 650I,BLACK/BLACK/SPORT/AUTO ]]>
</title>
...
<dc:title>
<![CDATA[2006 BMW 650I,BLACK/BLACK/SPORT/AUTO ]]>
</dc:title>
<dc:type>text</dc:type>
<dcterms:issued>2011-11-28T22:15:55-05:00</dcterms:issued>
</item>
Run Code Online (Sandbox Code Playgroud)

和Powershell脚本:

$rssFeed = [xml](New-Object System.Net.WebClient).DownloadString('http://philadelphia.craigslist.org/sss/index.rss')
foreach ($item in $rssFeed.rdf.item) { $item.title } 
Run Code Online (Sandbox Code Playgroud)

产生这个:

#cdata-section
--------------
2006 BMW 650I,BLACK/BLACK/SPORT/AUTO 
2006 BMW 650I,BLACK/BLACK/SPORT/AUTO 
Run Code Online (Sandbox Code Playgroud)

如何提取cdata-section?

我尝试了一些变体,例如$ item.title."#cdata-section"和$ item.title.InnerText,它们什么都不返回.我试过$ item.title | gm,我看到#cdata-section列为属性.我错过了什么?

谢谢.

man*_*lds 6

由于你有多个,title属性本身就是一个数组,所以以下应该有效:

$rss.item.title | select -expand "#cdata-section"
Run Code Online (Sandbox Code Playgroud)

要么

$rss.item.title[0]."#cdata-section"
Run Code Online (Sandbox Code Playgroud)

根据您的需要.