Powershell-如何解析内容:从RSS提要(XML)编码?
我正在尝试使用powershell从RSS提要解析数据 如何获取、标题、guid和内容:编码字段的内容 出于某种原因,我下面的代码只返回“…” 非常感谢您的帮助Powershell-如何解析内容:从RSS提要(XML)编码?,xml,powershell,rss,Xml,Powershell,Rss,我正在尝试使用powershell从RSS提要解析数据 如何获取、标题、guid和内容:编码字段的内容 出于某种原因,我下面的代码只返回“…” 非常感谢您的帮助 [xml]$hsg = Invoke-WebRequest http://technet.microsoft.com/en-us/security/rss/comprehensive #$hsg.rss.channel.item | select title #this prints the list of blog posts $C
[xml]$hsg = Invoke-WebRequest http://technet.microsoft.com/en-us/security/rss/comprehensive
#$hsg.rss.channel.item | select title #this prints the list of blog posts
$ContentNamespace = New-Object Xml.XmlNamespaceManager $hsg.NameTable
$ContentNamespace.AddNamespace("content", "http://purl.org/rss/1.0/modules/content/")
#$hsg.rss.channel.item #this prints the list of posts
$hsg.rss.channel.item.selectSingleNode("content:encoded", $ContentNamespace)
数据如下所示:
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rssdatehelper="urn:rssdatehelper" version="2.0">
<channel>
<title>Microsoft Security Content: Comprehensive Edition</title>
<link>http://technet.microsoft.com/security/bulletin</link>
<dc:date>Wed, 15 May 2013 08:00:00 GMT</dc:date>
<generator>umbraco</generator>
<description>Microsoft Security Content: Comprehensive Edition</description>
<language>en-US</language>
<item>
<title>
MS13-045 - Important : Vulnerability in Windows Essentials Could Allow Information Disclosure (2813707) - Version: 1.1
</title>
<link>
http://technet.microsoft.com/en-us/security/bulletin/ms13-045
</link>
<dc:date>2013-05-15T07:00:00.0000000Z</dc:date>
<guid>
http://technet.microsoft.com/en-us/security/bulletin/ms13-045
</guid>
<content:encoded>
<![CDATA[
Severity Rating: Important<br />
Revision Note: V1.1 (May 15, 2013): Corrected link to the download location in the Detection and Deployment Tools and Guidance section. This is an informational change only.<br />
Summary: This security update resolves a privately reported vulnerability in Windows Writer. The vulnerability could allow information disclosure if a user opens Writer using a specially crafted URL. An attacker who successfully exploited the vulnerability could override Windows Writer proxy settings and overwrite files accessible to the user on the target system. In a web-based attack scenario, a website could contain a specially crafted link that is used to exploit this vulnerability. An attacker would have to convince users to visit the website and open the specially crafted link.
]]>
</content:encoded>
</item>
Microsoft安全内容:综合版
http://technet.microsoft.com/security/bulletin
2013年5月15日星期三08:00:00 GMT
翁布拉科
Microsoft安全内容:综合版
恩美
MS13-045-重要信息:Windows Essentials中存在允许信息泄露的漏洞(2813707)-版本:1.1
http://technet.microsoft.com/en-us/security/bulletin/ms13-045
2013-05-15T07:00:00.0000000Z
http://technet.microsoft.com/en-us/security/bulletin/ms13-045
修订说明:V1.1(2013年5月15日):更正了指向检测和部署工具及指南部分下载位置的链接。这只是一个信息性更改。
摘要:此安全更新解决了Windows Writer中私下报告的漏洞。如果用户使用巧尽心思构建的URL打开Writer,该漏洞可能会导致信息泄露。成功利用该漏洞的攻击者可以覆盖Windows Writer代理设置并覆盖目标系统上用户可访问的文件。在基于web的攻击场景中,网站可能包含用于利用此漏洞的特制链接。攻击者必须说服用户访问该网站并打开精心制作的链接。
]]>
谢谢 试试这个:
$rss = [xml](Get-Content .\test.rss)
$rss.SelectNodes('//item') | % {
$posts += New-Object psobject -Property @{
Title = $_.Title.Trim()
Guid = $_.Guid.Trim()
Content = $_.Encoded."#cdata-section".Trim()
}
}
已解析数据的示例(由于示例中只有一项,因此数组仅包含一项):
$posts
标题Guid内容
----- ---- -------
MS13-045-重要提示:漏洞。。。http://technet.microsoft.com/... 严重程度分级:重要尝试以下方法:
$rss = [xml](Get-Content .\test.rss)
$rss.SelectNodes('//item') | % {
$posts += New-Object psobject -Property @{
Title = $_.Title.Trim()
Guid = $_.Guid.Trim()
Content = $_.Encoded."#cdata-section".Trim()
}
}
已解析数据的示例(由于示例中只有一项,因此数组仅包含一项):
$posts
标题Guid内容
----- ---- -------
MS13-045-重要提示:漏洞。。。http://technet.microsoft.com/... 严重性评级:重要您可以绕过将输出写入中间文件,跳过获取内容。Frode很好地将其打包成一个psobject,后者提供了解决方案
cls
$x=[xml](iwr 'https://technet.microsoft.com/en-us/security/rss/comprehensive').content
foreach ($y in $x.rss.channel.selectnodes('//item')) {
"`r`n`t$($y.title)"
$y.pubdate
$y.link
$y.encoded.'#cdata-section'
}
您可能会发现您的rss/atom返回的结构略有不同,我发现这对于不同的提要是必要的:
foreach ($y in $x.feed.entry)
IDE中的intellisense帮助我进行导航。您可以绕过将输出写入中间文件,跳过获取内容。Frode很好地将其打包成一个psobject,后者提供了解决方案
cls
$x=[xml](iwr 'https://technet.microsoft.com/en-us/security/rss/comprehensive').content
foreach ($y in $x.rss.channel.selectnodes('//item')) {
"`r`n`t$($y.title)"
$y.pubdate
$y.link
$y.encoded.'#cdata-section'
}
您可能会发现您的rss/atom返回的结构略有不同,我发现这对于不同的提要是必要的:
foreach ($y in $x.feed.entry)
IDE中的intellisense帮助我进行导航。就是这样!谢谢,@Graimer!成功了!谢谢,@Graimer!