Created
January 26, 2023 21:56
-
-
Save go2tom42/39342b07dea3ba9f8a0ed7a499a96120 to your computer and use it in GitHub Desktop.
FONToMASS downloader
This file contains hidden or 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
#CHANGE⌄ | |
$pages = 869 | |
#CHANGE^ | |
# DON'T CHANGE⌄ | |
Function Get-RedirectedUrl { | |
Param ( | |
[Parameter(Mandatory = $true)] | |
[String]$URL | |
) | |
$request = [System.Net.WebRequest]::Create($url) | |
$request.AllowAutoRedirect = $false | |
$response = $request.GetResponse() | |
If ($response.StatusCode -eq "Found") { | |
$response.GetResponseHeader("Location") | |
} | |
} | |
$BaseURL = "https://vk.com/topic-178186634_39300099?offset=" | |
$outerrange = ($pages -1) * 20 | |
$reg_expression = '/doc.*' | |
$dl = New-Object net.webclient | |
for ($offset = 0; $offset -le $outerrange; $offset += 20) { | |
$scraped_links = (Invoke-WebRequest -Uri "$BaseURL$offset").Links.Href | Get-Unique | |
$all_matches = ($scraped_links | Select-String $reg_expression -AllMatches).Matches | |
$urls = foreach ($url in $all_matches) { | |
$url.Value | |
} | |
foreach ($URL in $URLS) { | |
$FileName = ([System.IO.Path]::GetFileName((Get-RedirectedUrl "https://vk.com$($URL)"))).split('?')[0] | |
if (Test-Path -Path ".\$FileName" -PathType Leaf) { | |
$add = ([System.IO.Path]::GetRandomFileName().Split('.')[0]) | |
$FileName = "$FileName-DUP-$add" | |
} | |
$dl.Downloadfile( "https://vk.com$URL", ".\$FileName") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment