- # 下载微信图片
- $ProgressPreference = 'SilentlyContinue'
- Add-Type -AssemblyName System.Web
- [System.Net.ServicePointManager]::SecurityProtocol = 'Tls, Tls11, Tls12'
- $dstdir = [io.path]::Combine([environment]::GetFolderPath([environment+specialfolder]::Desktop), 'ABC') # 下载保存目录
- $di = [io.directory]::CreateDirectory($dstdir)
- $result = Invoke-WebRequest -Uri 'https://mp.weixin.qq.com/s/YtWEQ_kORUmh97sAEMwUjw' -SessionVariable session1 # 下载地址url - $result.Content 乱码:utf8解析成ANSI
- foreach ($img in $result.Images) {
- $src = if ($img.'data-src') { $img.'data-src' }else { $img.src }
- if (-not $src) { continue }
- $uri = [uri]$src
- $nvc = [System.Web.HttpUtility]::ParseQueryString($uri.Query)
- $wx_fmt = $nvc['wx_fmt']
- $picname = ($uri.Segments[-2] -replace '/') + ".${wx_fmt}"
- $picpath = [io.path]::Combine($di.FullName, $picname)
- "downloading: $src"
- Invoke-WebRequest -UseBasicParsing -Uri $uri -OutFile $picpath -WebSession $session1
- }
复制代码
|