【问题标题】:Saving webpage as MHTM file将网页另存为 MHTM 文件
【发布时间】:2010-11-02 23:30:37
【问题描述】:

给定一个特定的 URL,我正在尝试将该 URL 的内容下载为 MHT 文件。我考虑过编写解析器/爬虫,但认为必须有更快的方法。

我启动了 Powershell:

$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("http://www.example.com")
$ie.document.title # Just to verify the navigate worked

此时我找不到调用菜单命令的方法,尤其是 SaveAs。

任何帮助将不胜感激。

【问题讨论】:

标签: internet-explorer com powershell


【解决方案1】:

使用 VBScript

对于本地文件

cscript yourscriptname.vbs file:/test.html test.mht

对于远程文件

cscript yourscriptname.vbs http://www.test.com/test.html test.mht

-

Const adSaveCreateNotExist = 1
Const adSaveCreateOverWrite = 2
Const adTypeBinary = 1
Const adTypeText = 2

Set args = WScript.Arguments

if args.Count = 0 then
WScript.Echo "Usage: [CScript | WScript] mht_converter.vbs <html file> <mht filename>"
WScript.Quit 1
end if

Set objMessage = CreateObject("CDO.Message")
objMessage.CreateMHTMLBody args.Item(0)
SaveToFile objMessage, args.Item(1)

Sub SaveToFile(Msg, Fn)
Dim Strm, Dsk
Set Strm = CreateObject("ADODB.Stream")
Strm.Type = adTypeText
Strm.Charset = "US-ASCII"
Strm.Open
Set Dsk = Msg.DataSource
Dsk.SaveToObject Strm, "_Stream"
Strm.SaveToFile Fn, adSaveCreateOverWrite
End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-25
    • 2011-10-27
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多