{"id":14940,"date":"2022-12-16T11:58:34","date_gmt":"2022-12-16T11:58:34","guid":{"rendered":"http:\/\/www.max-sperling.bplaced.net\/?p=14940"},"modified":"2024-02-16T10:44:15","modified_gmt":"2024-02-16T10:44:15","slug":"download-files-without-logical-order","status":"publish","type":"post","link":"http:\/\/www.max-sperling.bplaced.net\/?p=14940","title":{"rendered":"Download files from page (listed in source)"},"content":{"rendered":"<p><strong>Scenario<\/strong><\/p>\n<p>You scroll a webpage an it loads files step by step and you want to download them. You check the source code of that page and the files are listed there.<\/p>\n<hr>\n<p><strong>Download<\/strong><\/p>\n<p>The following PowerShell script shows how to download the files based on the source file. <\/p>\n<pre>\r\nfunction Search-Items {\r\n    param ([string]$Text, [string]$Pattern)\r\n\r\n    $Text | Select-String $Pattern -AllMatches | Foreach-Object {\r\n        $Items += @($_.Matches.Value)\r\n    }\r\n\r\n    return $Items\r\n}\r\n\r\nfunction Download-Items {\r\n    param ([Parameter(ValueFromPipeline)] [string[]]$Items)\r\n\r\n    process {\r\n        foreach ($Item in $Items) {\r\n            Write-Output $Item\r\n            $File = $Item.Substring($Item.LastIndexOf(\"\/\") + 1)\r\n            Invoke-WebRequest $Item -OutFile $File\r\n        }\r\n    }\r\n}\r\n\r\n$ProgressPreference = \"SilentlyContinue\" # Suppresses progress bar\r\n\r\n$Url = \"https:\/\/website.com\/path\/to\/page\"\r\n$Request = Invoke-WebRequest $Url\r\n$Pattern = \"https:\/\/website.com\/[^,]*`.jpg\"\r\n\r\nSearch-Items $Request.Content $Pattern | Select-Object -Unique | Download-Items\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Scenario You scroll a webpage an it loads files step by step and you want to download them. You check<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false},"categories":[55],"tags":[],"_links":{"self":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/14940"}],"collection":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14940"}],"version-history":[{"count":1,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/14940\/revisions"}],"predecessor-version":[{"id":16825,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=\/wp\/v2\/posts\/14940\/revisions\/16825"}],"wp:attachment":[{"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14940"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.max-sperling.bplaced.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}