如何從PowerShell調用System.ServiceModel.Syndication.SyndicationFeed?如何在PowerShell中讀取ATOM XML
我正在嘗試從Powershell讀取RSS提要,並且需要遍歷提要,我想知道怎麼做才能做到這一點?
我找不到任何示例。
在此先感謝! 拉馬尼
如何從PowerShell調用System.ServiceModel.Syndication.SyndicationFeed?如何在PowerShell中讀取ATOM XML
我正在嘗試從Powershell讀取RSS提要,並且需要遍歷提要,我想知道怎麼做才能做到這一點?
我找不到任何示例。
在此先感謝! 拉馬尼
這就是我想出了在幾秒鐘:
$url = "http://stackoverflow.com/feeds/question/10589059"
[System.Reflection.Assembly]::LoadWithPartialName("System.ServiceModel") | Out-Null
[System.ServiceModel.Syndication.SyndicationFeed] $feed = [System.ServiceModel.Syndication.SyndicationFeed]::Load([System.Xml.XmlReader]::Create($url))
$feed | Get-Member
你真正要做的是解析XML使用PowerShell。這一個班輪將讓你從這個問題中的條目:
((New-Object Net.Webclient).DownloadString("http://stackoverflow.com/feeds/question/10589059") -as [xml]).feed.entry
它創建了一個新的Web客戶端,並下載URL,把它變成XML,然後就點包含到XML元素(你可以在PowerShell中做)。
這是一個非常簡單的功能,它包含了很多PowerShell的功能。類似的例子是布魯斯·帕耶特年代初「的PowerShell在行動」
希望這有助於
我得到了下面的錯誤與上面的代碼,你可以看看好嗎?無法找到類型[System.ServiceModel.Syndication.SyndicationFeed]:確保包含此類型的程序集已加載。 在線:7 char:108 + [System.ServiceModel.Syndication.SyndicationFeed] $ feed = [System.ServiceModel.Syndication.SyndicationFeed] <<<< :: Load([System.Xml.XmlReader] :: Create( $ URI)) + CategoryInfo:InvalidOperation:(System.ServiceM ... SyndicationFeed:String)[],RuntimeException + FullyQualifiedErrorId:TypeNotFound – user1358784
是否在您的GAC中安裝了System.ServiceModel?當你執行[System.Reflection.Assembly] :: LoadWithPartialName(「System.ServiceModel」)時,它會正常工作,當你單獨運行這條線時會發生什麼[System.Reflection.Assembly] :: LoadWithPartialName(「System.ServiceModel」) –
this this work fine line alsone – user1358784