2011-11-29 40 views
4

我试图使用PowerShell来读取RSS提要,我不能进PowerShell的解析

这里中提取CDATA段是饲料的片段(与切割成几个项目节省空间):

<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> 

而且PowerShell脚本:

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

将会产生这样的:

#cdata-section 
-------------- 
2006 BMW 650I,BLACK/BLACK/SPORT/AUTO 
2006 BMW 650I,BLACK/BLACK/SPORT/AUTO 

如何提取cdata部分?

我尝试了几个变体,例如$ item.title。“#cdata-section”和$ item.title.InnerText,它们什么都不返回。我试过$ item.title | gm,我看到#cdata部分列为属性。我错过了什么?

谢谢。

回答

5

既然你有这些的倍数,标题属性本身是一个数组,所以下面应该工作:

$rss.item.title | select -expand "#cdata-section" 

$rss.item.title[0]."#cdata-section" 

根据你所需要的。