Powershell可以很轻松的获取网页的信息并读取到对应的内容。如果对象的格式是XML或者Json,那就更容易处理了,一般经常使用invoke-restmethod和invoke-webrequest这两个命令。前者主要是获取Json格式的内容,后者可以获取整个网页的内容。
比如说我希望查询明天悉尼的天气如何。网上随便搜了一个提供API的站点
http://openweathermap.org/current#name
我打算搜索悉尼的,那么对应的格式是
http://api.openweathermap.org/data/2.5/weather"1.PNG" alt="wKioL1YTZcayHgafAAErC9Ji2JA626.jpg" src="/UploadFiles/2021-04-08/2015101011563615.jpg">
我们可以用invoke-restmethod直接获取这个结果,比如说
$b=invoke-restmethod "http://api.openweathermap.org/data/2.5/weather" $c=[pscustomobject]@{ 'Description'=$b.weather.description 'name'=$b.name 'windspeed'=$b.wind.speed }
我也可以直接使用invoke-webrequest抓取整个网页的内容,然后从Json的格式转换过来也是一样的
$a= Invoke-WebRequest -Uri "http://api.openweathermap.org/data/2.5/weather"$b=$a.Content | ConvertFrom-Json
类似的,如果我想获取一个博客的RSS的最新内容。可以使用invoke-webrequest抓取对应的XML文件,比如
[xml]$a= Invoke-WebRequest -Uri "http://blogs.msdn.com/b/powershell/rss.aspx“$a.rss.channel.Item | select title,pubdate
功能很强大,使用却很简单。
本文出自 “麻婆豆腐” 博客
更新日志
- 许景淳.1992-你来自何方【全美唱片】【WAV+CUE】
- 石欣卉.2007-剧欣卉集·完整电视剧主题精丫华纳】【WAV+CUE】
- 群星.2005-LOVE情歌集VOL.5.2CD【正东】【WAV+CUE】
- 孙悦.1996-伙伴【正大国际】【WAV+CUE】
- 纪钧瀚《钢琴阅读时光 雨中书店聆听轻音乐》[FLAC/分轨][399.62MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[320K/MP3][87.4MB]
- 证声音乐图书馆《走向自然 疗心爵士乐》[FLAC/分轨][184.94MB]
- 陈慧娴.2018-Priscilla-Ism演唱会3CD(2024环球红馆40复刻系列)【环球】【WAV+CUE】
- 郑秀文.1999-我应该得到(国)【华纳】【WAV+CUE】
- 陈家慧.2011-钢琴酒吧2CD【龙吟唱片】【WAV+CUE】
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[320K/MP3][45.01MB]
- 证声音乐图书馆《雨季 蓝调吉他 Rainy Blues》[FLAC/分轨][109.13MB]
- 赞多《序章》[320K/MP3][45.54MB]
- 许巍.2004-每一刻都是崭新的【步升大风】【WAV+CUE】
- 群星.2024-四方馆影视原声带【韶愔音乐】【FLAC分轨】