parsing - 我正在尝试使用Powershell解析非标准的RSS提要

标签 parsing powershell rss pinterest

我的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> &lt;p&gt;&lt;a href="http://pinterest.com/pin/329888741425045427/"&gt;&lt; img src="http://media-cache-lt0.pinterest.com/192x/bd/5e/7c/bd5e7cd628c21313d835a4e5c89d28ee.jpg"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt; Why You’ve Got to Have an #Elevator #Pitch - #marketing&lt;/p&gt; </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/

相关文章:

java - 从字符串中删除所有 'spaces'

parsing - 如何使用解析表证明左递归文法不在 LL(1) 中

parsing - 我如何解析 bool 逻辑?

ios - Objective-C iOS 根据定义解析字符串

powershell - 在 powershell 中执行 Enter-PSSession 时出现随机错误

java - 使 RSS 提要可点击

windows - 如何从 PowerShell 中的 dir 命令中删除当前路径?

powershell - 具有多个路径的 Get-ChildItem - 如果缺少目录则出错

ssl - 即使启用了 SSL,RSS Feed 仍因不安全而被阻止

java - 如何控制正在运行的java服务