我正在寻找一种方法来解析PowerShell中的RSS源(XML)以获取特定的字符串。该RSS(缩短)看起来像:解析XML并删除一些不需要的字符串并写入txt
<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 Address: 123.123.123.123.123.123, Country: AA URL: url2.com/filenamehere, IP Address: 123.123.123.123.123.123, Country: AA URL: url3.com/filenamehere, IP Address: 123.123.123.123.123.123, Country: AA
但我只对“URL:”后面的链接感兴趣,例如url1.com/filename。 那么,我可以请求您的协助,以便在“description”字段的第一个逗号后面删除开始的“URL:”和所有内容吗?此外,我想在每个网址前添加“http://”。
'-replace'^ URL:(。*?),。*','http: // $ 1'' –