Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##################
- ###patriots.win###
- ##################
- $downloadDirectory = "C:\Path\To\DownloadDirectory"
- # Create the directory if it doesn't exist.
- if (-not (Test-Path $downloadDirectory)) {
- New-Item -ItemType Directory -Path $downloadDirectory | Out-Null
- }
- # Loop through pages 1 to 113.
- for ($page = 1; $page -le 113; $page++) {
- $pageUrl = "https://www.archives.gov/research/jfk/release-2025?page=$page"
- Write-Host "Processing page ${page}: ${pageUrl}"
- try {
- $response = Invoke-WebRequest -Uri $pageUrl -UseBasicParsing
- }
- catch {
- Write-Error "Failed to retrieve page ${page}: ${pageUrl}"
- continue
- }
- $content = $response.Content
- # Use regex to extract all PDF links from the page.
- $regexPattern = 'href="([^"]+\.pdf)"'
- $matches = [regex]::Matches($content, $regexPattern)
- foreach ($match in $matches) {
- $pdfLink = $match.Groups[1].Value
- # If the link is relative, prepend the base URL.
- if ($pdfLink -notmatch '^https?://') {
- $pdfLink = "https://www.archives.gov" + $pdfLink
- }
- Write-Host "Downloading: ${pdfLink}"
- $fileName = [System.IO.Path]::GetFileName($pdfLink)
- $destinationPath = Join-Path -Path $downloadDirectory -ChildPath $fileName
- try {
- Invoke-WebRequest -Uri $pdfLink -OutFile $destinationPath -UseBasicParsing
- # Wait for 1 second after downloading a PDF
- Start-Sleep -Seconds 1
- }
- catch {
- Write-Error "Failed to download ${pdfLink}"
- }
- }
- }
- ##################
- ###patriots.win###
- ##################
Advertisement
Add Comment
Please, Sign In to add comment