我正在尋找一種方法來解析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'' –