Created
December 24, 2024 14:02
-
-
Save terremoth/a2b81fbaf5bb390a4a274bd8fbbe5016 to your computer and use it in GitHub Desktop.
get page id from URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = $args[0] | |
try { | |
$response = Invoke-WebRequest -Uri $url | |
} catch { | |
Write-Output $_.Exception | |
if ($_.Exception.Response.StatusCode -eq "404") { | |
Write-Host "Error: Page does not exist" | |
} else { | |
Write-Host "Error: Page could not be processed" -ForegroundColor red -BackgroundColor black | |
} | |
Exit | |
} | |
$content = $response.Content | select-string -Pattern "<!-- POST ID: (\d+) -->" | |
if ($content) { | |
# Write-Host $content.Matches.Value | |
$postId = $content.Matches.Groups[1].Value | |
Write-Host $postId | |
} else { | |
Write-Host "POST ID not found." | |
} |
Author
terremoth
commented
Dec 24, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment