【发布时间】:2018-03-24 10:39:08
【问题描述】:
我正在寻找一种在 PowerShell 中为特定字符串解析 rss 提要 (XML) 的方法。 RSS(缩短)看起来像:
<channel>
<title>title here</title>
<link>http://link.com</link>
<description>this is a description</description>
<language>en-us</language>
<item>
<title>title1</title>
<description>URL: url1.com/filenamehere, IP Address: 123.123.123.123.123.123, Country: AA</description>
</item>
<item>
<title>title2</title>
<description>URL: url2.com/filenamehere, IP Address: 123.123.123.123.123.123, Country: AA</description>
</item>
<item>
<title>title3</title>
<description>URL: url2.com/filenamehere, IP Address: 123.123.123.123.123.123, Country: AA</description>
</item>
我正在下载 RSS,并且能够解析我感兴趣的“描述”字段:
$rssFeed = [xml](New-Object System.Net.WebClient).DownloadString('http:/url2feed.com/rss/')
$rssFeed.rss.channel.item | Select-Object description -First 5
输出是:
URL:url1.com/filenamehere,IP地址:123.123.123.123.123.123,国家:AA URL:url2.com/filenamehere,IP地址:123.123.123.123.123.123,国家:AA URL:url3.com/filenamehere,IP地址:123.123.123.123.123.123,国家:AA但我只对“URL:”之后的链接感兴趣,例如url1.com/文件名。 那么,我可以请求您的帮助,请退出开头的“URL:”以及“描述”字段中第一个逗号之后的所有内容吗?此外,我想在每个 URL 之前添加“http://”。
【问题讨论】:
-
-replace '^URL: (.*?),.*', 'http://$1'
标签: xml powershell parsing rss