1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellでRSSフィードを取得

Posted at

新しい言語を覚える際は、自分が他の言語で書いたツールを移植してみることから始めることにしている。

そんなわけで、前にPythonで書いたRSSリーダ(マルチコア対応)を書き換えてみた。本当はマルチコアで動かしたかったが、MacOSで動くPowerShellではworkflowが実装されてないので、とりあえずシングルスレッドで動かす。

#!/usr/local/bin/pwsh 
$regex = Read-Host "keyword"

$urls =@(
    'https://gizmodo.com/rss',
    'https://www.cnet.com/rss/all/',
    'https://techcrunch.com/feed/'
)

foreach ( $url in $urls ){
    $f = [XML](Invoke-WebRequest $url)
    foreach( $item in $f.rss.channel.item ) {
        if ($item.description -match $regex ){
            Write-Host $item.title
            Write-Host $item.link
            Write-Host ""
        }
    }
}

お気付きの通り、かなりシンプル。特にXMLが信じられないほど楽だ。

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?