Guest User

jfk file downloader for patriots.win

a guest
Mar 18th, 2025
469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 1.68 KB | Source Code | 0 0
  1. ##################
  2. ###patriots.win###
  3. ##################
  4. $downloadDirectory = "C:\Path\To\DownloadDirectory"
  5.  
  6. # Create the directory if it doesn't exist.
  7. if (-not (Test-Path $downloadDirectory)) {
  8.     New-Item -ItemType Directory -Path $downloadDirectory | Out-Null
  9. }
  10.  
  11. # Loop through pages 1 to 113.
  12. for ($page = 1; $page -le 113; $page++) {
  13.     $pageUrl = "https://www.archives.gov/research/jfk/release-2025?page=$page"
  14.     Write-Host "Processing page ${page}: ${pageUrl}"
  15.  
  16.     try {
  17.         $response = Invoke-WebRequest -Uri $pageUrl -UseBasicParsing
  18.     }
  19.     catch {
  20.         Write-Error "Failed to retrieve page ${page}: ${pageUrl}"
  21.         continue
  22.     }
  23.  
  24.     $content = $response.Content
  25.  
  26.     # Use regex to extract all PDF links from the page.
  27.     $regexPattern = 'href="([^"]+\.pdf)"'
  28.     $matches = [regex]::Matches($content, $regexPattern)
  29.    
  30.     foreach ($match in $matches) {
  31.         $pdfLink = $match.Groups[1].Value
  32.        
  33.         # If the link is relative, prepend the base URL.
  34.         if ($pdfLink -notmatch '^https?://') {
  35.             $pdfLink = "https://www.archives.gov" + $pdfLink
  36.         }
  37.        
  38.         Write-Host "Downloading: ${pdfLink}"
  39.         $fileName = [System.IO.Path]::GetFileName($pdfLink)
  40.         $destinationPath = Join-Path -Path $downloadDirectory -ChildPath $fileName
  41.        
  42.         try {
  43.             Invoke-WebRequest -Uri $pdfLink -OutFile $destinationPath -UseBasicParsing
  44.             # Wait for 1 second after downloading a PDF
  45.             Start-Sleep -Seconds 1
  46.         }
  47.         catch {
  48.             Write-Error "Failed to download ${pdfLink}"
  49.         }
  50.     }
  51. }
  52. ##################
  53. ###patriots.win###
  54. ##################
Advertisement
Add Comment
Please, Sign In to add comment