我的Pinterest提要将RSS标题截断为20个字符,我需要在描述末尾解析出“img src”和较长的文本。
我的代码非常简单,但是我无法弄清楚如何使新标题变成“为什么要有#Elevator #Pitch-#marketing”
$feed = [xml](New-Object System.Net.WebClient).DownloadString('http://pinterest.com/bigoals365/feed.rss')
$feed.rss.channel.Item | select title, link, description | Out-GridView
我也尝试过Invoke-WebRequest,并且可以用于基本检索,但是对描述的解析让我很头疼。
我的供稿看起来像这样(RSS的一行):
<item><title>Why You’ve Got to Ha</title><link>http://pinterest.com/pin/329888741425045427/</link> <description> <p><a href="http://pinterest.com/pin/329888741425045427/">< img src="http://media-cache-lt0.pinterest.com/192x/bd/5e/7c/bd5e7cd628c21313d835a4e5c89d28ee.jpg"></a></p><p> Why You’ve Got to Have an #Elevator #Pitch - #marketing</p> </description> <pubDate>Wed, 06 Mar 2013 21:59:55 +0000</pubDate><guid>http://pinterest.com/pin/329888741425045427/ </guid></item>
任何帮助将非常感激!
最佳答案
也许这样吗?
$feed.rss.channel.item | %{
if ($_.description -match '.*<img src="([^"]+)".*<p>(.*)</p>') {
$_.title = $matches[2];
$_.link = $matches[1]
}
$_
} | select title, link, description | Out-GridView
希望这可以帮助
/弗雷德里克
关于parsing - 我正在尝试使用Powershell解析非标准的RSS提要,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15261620/