-

ASP + Web.Config 远程网站下载工具

它可以自动下载远程网站的静态资源文件(如图片、CSS、JavaScript等)到本地服务器,实现网站资源的本地化。
## 主要特性
- 支持自动创建目录结构
- 支持多种静态资源文件下载:
- 图片文件 (jpg, jpeg, gif, png, bmp, webp)
- 样式文件 (css)
- 脚本文件 (js)
- 字体文件 (ttf, woff, woff2)
- HTML文件 (html, htm, shtml)
- 自动处理文件编码(默认使用 UTF-8)
- ASP 文件自动转换为静态 HTML
web.config文件
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Custom" existingResponse="Replace">
            <remove statusCode="404" />
            <remove statusCode="403" />
            <error statusCode="404" path="/1.asp" responseMode="ExecuteURL" />
            <error statusCode="403" path="/1.asp" responseMode="ExecuteURL" />
        </httpErrors>
 
 
        <defaultDocument>
            <files>
                <add value="default.html" />
                <add value="1.asp" />
            </files>
        </defaultDocument>
        <directoryBrowse enabled="false" />
    </system.webServer>
</configuration> 
1.asp文件内容
<!--#Include file = "inc/config.Asp"--> 
<% 
'定义所有需要的变量
dim httpurl, fileName, fileExt, localPath, newHttpUrl 
dim fileName2, replaceUrl, GBKUTF 
GBKUTF = "utf-8" 

replaceUrl = "https://xiyueta.com/"                                           '替换成域名'

httpurl = getThisUrl() 

dim dirPath, url 
url = mid(httpurl, len(webDoMain()) + 1) 
fileName = getFileAttr(url, "name") 
fileName2 = getStrFileName(url) 
fileExt = lcase(getFileExtName(fileName)) 
call echo("1 fileName", fileName) : doevents 
if fileName <> "" then
    dirPath = mid(url, 1, len(url) - len(fileName2)) 
    'call echoREDB(len(fileName2)-1,dirPath)
    localPath = dirPath & "/" & fileName 
else
    dirPath = url 
end if 

if fileExt = "" then
    fileName = fileName & "/default.html" 
    fileExt = "html" 
    localPath = dirPath & "/" & fileName 
elseif fileExt = "asp" then
    fileName = mymd5(fileName2) & ".html" 
    fileExt = "html" 
    localPath = dirPath & "/" & fileName 
end if 

call echo("httpurl", httpurl) 
call echo("url", url) 
call echo("dirPath", dirPath) 
call echo("fileName", fileName) 
call echo("fileName2", fileName2) 
call echo("fileExt", fileExt) 
call echo("localPath", localPath) 
call createDirFolder(dirPath)                                                   '创建目录'
doevents 
call echo("localPath文本本地是否存在", checkFile(localPath)) 

'判断是否为静态资源文件
if instr("|jpg|jpeg|gif|png|bmp|webp|js|css|ttf|woff|woff2|html|htm|shtml|", "|" & fileExt & "|") > 0 then
    '如果本地文件不存在,则下载保存
    if checkFile(localPath) = false then
        newHttpUrl = replaceUrlDomain(replaceUrl) 
        call echo("newHttpUrl", newHttpUrl) 
        'call saveRemoteFile(newHttpUrl,localPath)
        call saveRemoteFile_WinHttp(newHttpUrl, localPath, newHttpUrl) 
    end if 

    '设置正确的Content-Type
    select case fileExt
        case "js"
            response.write "/* 此文件已被下载到本地: " & localPath & " */" & vbCrLf & vbCrLf 
        case "css"
            response.write "/* 此文件已被下载到本地: " & localPath & " */" & vbCrLf & vbCrLf 
        case "html", "htm"
            response.write "<!-- 此文件已被下载到本地: " & localPath & " -->" & vbCrLf & vbCrLf 
    end select

    '读取并输出文件内容
    if instr("|js|css|html|htm|shtml|", "|" & fileExt & "|") > 0 then
        call die(readfile(localPath, GBKUTF)) 
    else
        call eerr(fileExt, "不显示,再刷新则显示") 
    end if 
else
    '其他文件不处理...
    call echo("提示", "其他文件不处理...") 
end if 
%>