Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


An easy VBS just to save a web-page to MHT...

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,53000
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> An easy VBS just to save a web-page to MHT...
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 An easy VBS just to save a web-page to MHT... - 10/24/2007 9:31:40 PM   
  asgarcymed

 

Posts: 14
Score: 0
Joined: 10/24/2007
Status: offline
I want to create an easy VBS to save a web-page to MHT (MHTML). I saw many examples through a google's search, but they were very confusing because all of them also intended to send an eMail after saving the MIME file. I just want to save a web-page to MHT; not to send eMail!!

Here are some "fragments of code" I saw:


Set cdo_msg = CreateObject ("CDO.Message")

Set ado_stream = CreateObject ("ADODB.Stream")

.CreateMHTMLBody

.GetStream

.DataSource.SaveToObject

.SaveToFile


Can you please help me to make an easy VBS just to save a web-page to MHT?

Thanks in advance.
Best regards.
 
 
Post #: 1
 
 RE: An easy VBS just to save a web-page to MHT... - 10/24/2007 9:48:24 PM   
  DiGiTAL.SkReAM


Posts: 1157
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Heh, I saw this over at Experts Exchange as well.
If you have a script ath will email the page after creating/getting it, post that code, and we can help you trim it down to just save the file rather than emailing it.

Be aware, however, that while you most likely have benign intentions, some AV software view any vbs that works with web pages as a virus/trojan.
Had a huge script deleted out from underneath of me one time because Norton decided it was a trojan.  Grrrr.

_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to asgarcymed)
 
 
Post #: 2
 
 RE: An easy VBS just to save a web-page to MHT... - 10/24/2007 10:40:03 PM   
  asgarcymed

 

Posts: 14
Score: 0
Joined: 10/24/2007
Status: offline
All examples seems to be totally wrong (I tried copy-paste and always got errors).
Here is one:

Set cdo_message_object = CreateObject("CDO.Message")
Set stream_ado_object = CreateObject("ADODB.Stream")
cdo_message_object.CreateMHTMLBody "http://en.wikipedia.org/wiki/Array", 0, "",""
stream_ado_object.GetStream
stream_ado_object.SaveToFile "C:\array.mht"

The line

cdo_message_object.CreateMHTMLBody (...)

always gives error!!! I tried:

cdo_message_object.CreateMHTMLBody "http://en.wikipedia.org/wiki/Array", 0, "",""

cdo_message_object.CreateMHTMLBody (http://en.wikipedia.org/wiki/Array, 0, "","")

cdo_message_object.CreateMHTMLBody ("http://en.wikipedia.org/wiki/Array", 0, "","")

None worked :(

(in reply to asgarcymed)
 
 
Post #: 3
 
 RE: An easy VBS just to save a web-page to MHT... - 10/25/2007 3:01:46 AM   
  asgarcymed

 

Posts: 14
Score: 0
Joined: 10/24/2007
Status: offline
What a great mystery!!!!!

Take a look at this VBS:
quote:


'MakeMHT.vbs

Const adSaveCreateNotExist = 1
Const adSaveCreateOverWrite = 2
Const adTypeBinary = 1 'Binary data
Const adTypeText = 2 '(Default) Text data

URL = "http://www.paulsadowski.com/"
DiskFile = "C:\test.mht"

Set objMessage = CreateObject("CDO.Message")
objMessage.CreateMHTMLBody URL
SaveToFile objMessage, DiskFile

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


This works fine.

Now look at this one (everything is the same, except the URL itself):
quote:


'MakeMHT.vbs

Const adSaveCreateNotExist = 1
Const adSaveCreateOverWrite = 2
Const adTypeBinary = 1 'Binary data
Const adTypeText = 2 '(Default) Text data

URL = "http://www.yahoo.com/"
DiskFile = "C:\test.mht"

Set objMessage = CreateObject("CDO.Message")
objMessage.CreateMHTMLBody URL
SaveToFile objMessage, DiskFile

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


Why the hell this second scripts causes an error - «(12,1) CDO.Message.1: Invalid syntax»??????????
Everything is exactly the same except:
URL = "http://www.paulsadowski.com/" => => URL = "http://www.yahoo.com/"

(in reply to asgarcymed)
 
 
Post #: 4
 
 RE: An easy VBS just to save a web-page to MHT... - 10/25/2007 3:17:27 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well, just l;ooking for quick differences, the two pages use different encoding.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to asgarcymed)
 
 
Post #: 5
 
 RE: An easy VBS just to save a web-page to MHT... - 10/25/2007 3:27:42 AM   
  asgarcymed

 

Posts: 14
Score: 0
Joined: 10/24/2007
Status: offline
How can I preview such different encoding? How many different encoding types exists? Is it possible to create a "general"/"all web-pages" mht saver?

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: An easy VBS just to save a web-page to MHT... - 10/25/2007 3:34:28 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Well, I'm not a web dude so I doubt I will have the best answers.

quote:

  How many different encoding types exists?


Not sure, but I think the technical term is "buttload". Look here: http://www.iana.org/assignments/character-sets

quote:

  How can I preview such different encoding?


Again I am not sure, but you may want to lookup the properties and methods of the Message object to see what encodings it is limited to.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to asgarcymed)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> An easy VBS just to save a web-page to MHT... Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts