需要帮助通过网站解析专辑的发行日期

时间:2019-07-01 22:40:27

标签: html powershell parsing scripting compare

我是PowerShell的新手,并且喜欢尝试的所有新功能,我喜欢使用自己感兴趣的东西进行学习。我试图弄清楚脚本的伪代码。我想制作一个通过https://en.wikipedia.org/wiki/List_of_years_in_hip_hop_music解析的自动化脚本。然后,每年选择每张专辑,并将当前日期与专辑的发行日期进行比较,如果将其与“ Monday”和“ Day”相匹配,则将其添加到带有艺术家和专辑标题的列表中,然后通过电子邮件将日期列表最终通过电子邮件发送给我专辑发行。不是寻找确切的代码,而是寻找从哪里开始和应该采取的步骤。

$album = Invoke-WebRequest -uri "https://en.wikipedia.org/wiki/Blonde_(Frank_Ocean_album)"
$today = Get-Date -Format yyyy-M-dd
$date = $album.AllElements | where tagname -EQ "td" | where class -EQ "published" | select innertext
$date 

到目前为止,我所拥有的全部。我从一张专辑开始,然后返回发行日期。

1 个答案:

答案 0 :(得分:0)

脚本类似于:

$YIHHM = Invoke-WebRequest 'https://en.wikipedia.org/wiki/List_of_years_in_hip_hop_music'
$SongPages = ForEach($YearLink in ($YIHHM.Links | Where {$_.href -match '/wiki/.*in_hip_hop_music'})){
    $ThisYear = Invoke-WebRequest "https://en.wikipedia.org$($YearLink.href)"
    $ThisYear.Links | Where{$_.href -match '^/wiki/'} | ForEach-Object{
        $Page = Invoke-WebRequest "https://en.wikipedia.org$($_.href)"
        #Check if there's a published class, and if there is output the page
        If($_.tagname -eq 'td' and $_.class -eq 'published'){$Page}
    }
}

然后,您需要过滤$SongPages的确切发布日期(与当前日期相比),以查看Month和Day属性是否匹配。我想您可以在检查是否有已发布的类的同一循环中执行此操作。然后,您只需要确定歌曲即可。由于链接的数量以及一小部分将成为歌曲链接的原因,这仍将永远消失。

相关问题