Download HTML page

本文介绍了如何利用MSXML2.XMLHTTP对象下载指定URL的HTML页面,并提供了如何发送用户名和密码进行安全验证的方法。
Download HTML page
With CreateObject("MSXML2.XMLHTTP")
.open "GET", "http://www.rgagnon.com/howto.html", False
.send
WScript.Echo .responseText
End With
If you need to send an username and password :
With CreateObject("MSXML2.XMLHTTP")
.open "GET", "http://www.rgagnon.com/secure/example.html", False, _
myusername, mypassword
.send
WScript.Echo .responseText
End With

转载于:https://www.cnblogs.com/HappyQQ/archive/2008/02/26/1081446.html

### 如何使用 `<a>` 标签的 `download` 属性来下载 HTML 文件 HTML 提供了一个简单的方法通过 `<a>` 标签及其 `download` 属性让用户能够下载指定资源。当设置此属性时,点击链接会触发浏览器下载目标文件而非导航到该位置。 #### 基本语法 ```html <a href="path/to/file.html" download="filename.html">Download</a> ``` 这里的关键部分在于: - **href**: 指向要被下载的内容路径。 - **download**: 可选参数,用于建议保存文件名;如果省略,则默认采用 URL 的最后一部分作为文件名。 #### 实际应用案例 为了创建一个可以下载特定 HTML 文档的功能按钮,可按照如下方式编写代码片段: ```html <!-- 下载名为 example.html 的本地文件 --> <a href="./example.html" download="myExampleFile.html"> Click here to Download Example File </a> <!-- 或者动态生成并立即提供给用户下载 --> <script type="text/javascript"> function createAndDownloadHtml() { const content = ` <!DOCTYPE html> <html lang="en"> <head><title>Dynamic Page</title></head> <body><h1>Hello from dynamically created page!</h1></body> </html>`; var blob = new Blob([content], {type : 'text/html'}); var link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = "dynamicPage.html"; link.click(); } </script> <button onclick="createAndDownloadHtml()">Generate and Download Dynamic HTML</button> ``` 上述 JavaScript 函数展示了如何即时构建一段简单的 HTML 字符串,并将其转换成可供下载的对象。这使得即使服务器端不托管实际文件也可以实现文件分发功能[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值