我正在尝试使用powershell阅读rss提要,我无法在提要中提取cdata-section
下面是提要的一个片段(为了节省空间,删除了一些条目):
<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-section?
我尝试了一些变体,如$item.title。"#cdata-section"和$item.title。InnerText不返回任何东西。我试过$item。title | gm,我看到#cdata-section作为属性列出。我错过了什么?
谢谢。
由于您有多个这样的属性,因此title属性本身将是一个数组,因此以下内容应该可以工作:
$rss.item.title | select -expand "#cdata-section"
或
$rss.item.title[0]."#cdata-section"
根据你的需要