powershell - 解析 RSS,如果日期与当前日期匹配,则继续下载
问题描述
想法是检查 RSS 提要<updated> </updated>
是否更新了 RSS 更新标头与当前运行的日期匹配,然后继续下载。
示例 RSS 提要:
<?xml version="1.0" encoding="UTF-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text"> Updates</title>
<subtitle type="html"><![CDATA[Latest updates]]></subtitle>
<link href="http://website/website.rss"></link>
<id>http://website</id>
<link rel="alternate" type="text/html" href="http://website/website.rss" ></link>
<link rel="self" type="application/atom+xml" href="https://website/site/download" ></link>
<logo>http://website/website</logo>
<updated>2020-03-28 T17:32:48+00:00</updated>
<entry>
<author>
<name>ueam</name>
</author>
<title type="text"><![CDATA[2.0.4516]]></title>
<link rel="alternate" type="text/html" href="https://website/site/download"></link>
<id>https://website/site/download</id>
<summary type="html"><![CDATA[<ul>
<li>Patched for March 23rd update</li>
<li>Fixed known bug JIRA</li>
</ul>]]></summary>
<content type="html"><![CDATA[]]></content>
<updated>2020-03-28 17:32:48</updated>
</entry>
<entry>
<author>
<name>Team</name>
</author>
<title type="text"><![CDATA[2.0.4516]]></title>
<link rel="alternate" type="text/html" href="https://website/site/download"></link>
<id>https://website/site/download</id>
<summary type="html"><![CDATA[<ul>
<li>
Patch for March 23rd update
</li>
</ul>]]></summary>
<content type="html"><![CDATA[]]></content>
<updated>2020-03-28 17:32:48</updated>
</entry>
<entry>
<author>
<name>Team</name>
</author>
<title type="text"><![CDATA[2.0.4514]]></title>
<link rel="alternate" type="text/html" href="https://website/site/download></link>
<id>https://website/site/download</id>
<summary type="html"><![CDATA[<ul>
<li>Fixed Bug</li>
这里
<updated>2020-03-28 17:32:48</updated>
显示如果我今天正在运行然后将继续下载,因为它与当天匹配
然后将通过调用下载
Invoke-WebRequest -uri https://website/site/download
我只是不确定如何解析 RSS 以查看“更新”并与当前日期进行比较,如果日期匹配则继续下载。
更新:我尝试了以下
#Grab RSS
$rssString = Invoke-WebRequest "http://website/website.rss"
# convert rss to xml
$xml = [xml] $rssString
# select the <updated> node
$updateString = $xml.SelectSingleNode("/feed/updated").innerText
# convert string to date
$date = Get-Date $updateString
# compare to todays date
if($date.Date -eq (Get-Date).Date){
# proceed to download
}
您收到此错误:获取日期:无法将参数“日期”绑定到目标。异常设置“日期”:“无法将 null 转换为类型“System.DateTime”。”
当你跑
$更新字符串
什么都没有返回并且是空白的,似乎更新的节点没有被读取
解决方案
RSS 是 xml,所以这样对待它:)
<updated>
根目录下的节点似乎<feed>
反映了最新更新,因此请抓住:
# convert rss to xml
$xml = [xml]$rssString;
# select the <updated> node
$updateString = $xml.SelectSingleNode("/feed/updated").innerText
# convert string to date
$date = Get-Date $updateString
# compare to todays date
if($date.Date -eq (Get-Date).Date){
# proceed to download
}
推荐阅读
- google-cloud-platform - 我如何训练说泰米尔语名称(泰米尔族)作为 Google NLP 中的人的一部分
- bigcartel - 如何在产品页面上获取产品图片网址?
- php - XML 读取孩子的 id?
- python - AttributeError:部分初始化的模块“pandas”没有属性“DataFrame”
- javascript - 我的代码在 codepen 上工作,但不在我的编辑器上
- java - 在同一个 osgi 包中可以有两个服务接口吗?
- r - Mac上的C50包安装错误:C编译器无法创建可执行文件
- android - 如何检测在 Youtube Autoplay 新闻提要等回收站视图中查看可见性(80% 左右)在可见约 80 时播放视频
- android - androidx.constraintlayout.widget.Constraints VS androidx.constraintlayout.widget.ConstraintLayout?
- flutter - 如何将 Flutter 中的传感器流转换为频率较低的流?