2009-06-15 192 views
0

給定一個特定的URL,我試圖將該URL的內容作爲MHT文件下載。我認爲寫一個解析器/爬行器,但認爲必須有一個更快的方法。將網頁保存爲MHTM文件

我解僱了PowerShell的:

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

在這一點上我無法找到一個方法來調用菜單命令,尤其另存爲。

任何幫助,將不勝感激。

+0

正如你可以看到http://msdn.microsoft。 com/en-us/library/aa752084(VS.85).aspx無法調用SaveAs只有導航功能 – jitter 2009-06-15 11:15:03

回答

2

使用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