Powershell インスタグラムの保存済み画像をダウンロードするスクリプト
ダウンロードしたい画像をinstagramウェブページで表示する。
ソースをダウンロードする。
次の設定する。
$path
$invesfield
$investargets
$imagesfolder
ソースをダウンロードする。
次の設定する。
$path
$invesfield
$investargets
$imagesfolder
#テンプレートフォルダー
$path = "E:\OneDrive\ドキュメント\WindowsPowerShell Scripts"
#捜査フィールド
$invesfield = "インスタ保存画像URL抽出"
#捜査対象フォルダ
$investargets = "捜査対象"
#画像保存フォルダ
$imagesfolder = "ダウンロード画像"
#捜査結果保存ファイル
$output = Join-Path (Join-Path $path $invesfield) (Join-Path $investargets $imagesfolder)
#HTMLを捜査(ソース)
$investarget = Get-ChildItem (Join-Path (Join-Path $path $invesfield) $investargets) -recurse -Include *.html | Select-Object | Where-Object {-not $_.PSIsContainer}
$investarget
$tagsfromhtml = @()
$investarget | ForEach-Object {
$tagsfromhtml += [regex]::Matches((Get-Content $_),"src="(.*?)"") | foreach{$_.Groups[1].Value.TrimEnd()}
}
#保存
$tags = $tagsfromhtml -replace "s640x640/",""# | Select-Object –Unique | Sort-Object
$tags | foreach {
$downloadUrl = New-Object System.Uri ($_)
#$downloadUrl
$outputfile = Join-Path $output ([System.IO.Path]::GetFileName($_))
#$outputfile
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputfile
}