本帖最后由 went 于 2020-10-22 23:06 编辑
保存成test.bat
和pr6n.txt放到一起运行,图片保存在word文件夹中- @cd /d "%~dp0" & mkdir "word" >nul 2>nul & powershell -c "Get-Content '%~0' | Select-Object -Skip 1 | Out-String | Invoke-Expression" & pause&exit
- [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web")
- $Script:xhr=New-Object -ComObject "MSXML2.ServerXMLHTTP"
- $Script:count=0
- function Download-Image($key){
- $name = '{0:X4}' -f ([int]$key[0])
- if(Test-Path (".\word\"+$name+".png") -ErrorAction SilentlyContinue){
- Write-Host ("skip download: .\word\"+$name+".png")
- return
- }
- $png = [System.IO.File]::Create(".\word\"+$name+".png")
- $url = "https://penji-gakushu.com/shop/font/preview/d/?font_id=33&str="+[System.Web.HttpUtility]::UrlEncode($key)+"&size=220&bg=ffffff&font=000000"
- $Script:xhr.abort()
- $Script:xhr.open("GET",$url,$false)
- $Script:xhr.send()
- if($Script:xhr.status -ne 200) {
- Write-Host ("failed:"+$Script:xhr.status+" "+$Script:xhr.statusText) -ForegroundColor Red
- $png.Dispose()
- return
- }
- $bytes = $Script:xhr.responseBody
- $png.Write($bytes,0,$bytes.Count)
- $png.Name
- $png.Dispose()
- $Script:count += 1
- [System.Console]::Title = "" + $Script:count
- }
- Get-Content "pr6n.txt" -Encoding UTF8 | foreach { Download-Image -key $_.Trim() }
复制代码
|