我有以下脚本,其中包含一些 RegEx 来捕获此站点上的特定信息。
$Top40Response = Invoke-WebRequest -UseBasicParsing -Uri 'https://www.radioinfo.com.au/knowledge/chart'
$Top40Response.Content -match '<td\Wclass="twRank">[\s\S]+artist">([^<]*)'
$matches
Run Code Online (Sandbox Code Playgroud)
这是匹配最后一个“艺术家”。我想要做的就是制作它,以便它会按照从上到下的顺序贯穿并匹配此页面上的每个艺术家。
PowerShell-match
只返回第一个匹配项。您必须使用Select-String
with-AllMatches
参数 or [regex]::Matches
。
Select-String
:
$Top40Response = Invoke-WebRequest -UseBasicParsing -Uri 'https://www.radioinfo.com.au/knowledge/chart'
$Top40Response.Content |
Select-String -Pattern '<td\s+class="artist">(.*?)<\/td>' -AllMatches |
ForEach-Object {$_.Matches} |
ForEach-Object {$_.Groups[1].Value}
Run Code Online (Sandbox Code Playgroud)
[regex]::Matches
:
$Top40Response = Invoke-WebRequest -UseBasicParsing -Uri 'https://www.radioinfo.com.au/knowledge/chart'
$Top40Response.Content |
ForEach-Object {[regex]::Matches($_, '<td\s+class="artist">(.*?)<\/td>')} |
ForEach-Object {$_.Groups[1].value}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3464 次 |
最近记录: |