Internet explorer 将网页另存为MHTM文件

Internet explorer 将网页另存为MHTM文件,internet-explorer,com,powershell,Internet Explorer,Com,Powershell,给定一个特定的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 此时,我找不到调用菜单命令的方法,尤其是S

给定一个特定的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

任何帮助都将不胜感激。

使用VBScript

对于本地文件

cscript yourscriptname.vbs file:/test.html test.mht
用于远程文件

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

Const adSaveCreateNotExist=1
常量adSaveCreateOverWrite=2
常量adTypeBinary=1
常量adTypeText=2
Set args=WScript.Arguments
如果args.Count=0,则
Echo“用法:[CScript|WScript]mht_converter.vbs”
WScript.Quit 1
如果结束
Set objMessage=CreateObject(“CDO.Message”)
objMessage.CreateMHTMLBody参数项(0)
SaveToFile对象消息,参数项(1)
子存储文件(Msg,Fn)
Dim Strm,Dsk
设置Strm=CreateObject(“ADODB.Stream”)
Strm.Type=adTypeText
Strm.Charset=“US-ASCII”
标准开启
设置Dsk=Msg.DataSource
Dsk.SaveToObject Strm,“\u流”
Strm.SaveToFile Fn,adSaveCreateOverWrite
端接头
从中可以看出,无法调用SaveAs-only导航函数
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