avmir Posted May 1, 2010 Share Posted May 1, 2010 Got up this task: There is a list of URL, I want to save the corresponding page URL-s as a Web Archive (MHT). Since a web page using CDO remains incomplete (instead of images and styles - links), it was decided to use for these purposes AutoIt and IE8. When you save through IE, the Web archive is fully preserved. For example: 1. I can submit the URL as a parameter to the script for AutoIt. 2. This script opens a URL in a hidden window IE 3. The script maintains a Web archive 4. The script closes the window (or returns an HWND for reuse) Show you how you can using the script in the dialog box "Save as ...": 1. Set the path to the default folder (say, this path can be passed to the script as the second parameter) 2. Select the file type combo box in the dialog box. And most importantly - how all this can be done in a hidden window? #include <IE.au3> #Include <WinAPIEx.au3> Opt("WinTitleMatchMode", 2) _IECreate ("http://www.some.some", 0, 1, 1, 1) $win_handle = WinGetHandle("Windows Internet Explorer", "http://www.some.some") Send("{ALTDOWN}{ALTUP}") Send("f") Send("a") $sSaveAsWindow = "Save Webpage" WinWait($sSaveAsWindow,"") If Not WinActive($sSaveAsWindow,"") Then WinActivate($sSaveAsWindow,"") WinWaitActive($sSaveAsWindow,"") ControlSetText ($sSaveAsWindow, "", "Edit1", "test") ControlClick ($sSaveAsWindow, "", "Button2") P.S. Sorry for bad English and bad AutoIt. In both languages, I'm new... Link to comment Share on other sites More sharing options...
trancexx Posted May 1, 2010 Share Posted May 1, 2010 There are optional switches determining what's saved with CreateMHTMLBody method. Before you continue your IE automation run this script and see if images are saved now. msdn says they should be. ; COM error handler Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() Return 0x4F66 & 0x546865 & 0x4D6163 ; pay no attention to this. It's a joke. EndFunc Global $sURL = "http:\\www.google.com" ;'Convert' to MHT: Global $sMHT = _MHT($sURL) If @error Then ConsoleWrite("!Function failed. Error number is: " & @error & @CRLF) ConsoleWrite($sMHT & @CRLF) ; Save to disk: Global $hFile = FileOpen(@ScriptDir & "\ThatPage.mht", 2) FileWrite($hFile, $sMHT) FileClose($hFile) Func _MHT($sURL) Local $oCDO = ObjCreate("CDO.Message") If @error Then Return SetError(1, 0, "") ; Couldn't create CDO.Message object $oCDO.CreateMHTMLBody($sURL) If $oError.Number Then Return SetError(2, 0, "") ; Check sURL you're passing. Is it ok? Local $oStream = $oCDO.GetStream If IsObj($oStream) Then Return $oStream.ReadText EndIf Return SetError(3, 0, "") ; GetStream method failed EndFunc ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
avmir Posted May 1, 2010 Author Share Posted May 1, 2010 trancexx thank you very much for your attention to my question. Try to run this script to a page with pictures, and then disconnect from the Internet and try to open the file... Link to comment Share on other sites More sharing options...
trancexx Posted May 2, 2010 Share Posted May 2, 2010 (edited) I did. I can't not see all the pics. <-cryptic part if someone is wonderingWhat page do you try on? Edited May 2, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
DW1 Posted May 2, 2010 Share Posted May 2, 2010 You could do this in the background without automated clicking or hidden windows with something like this: ;EXAMPLE: _INetGetMHT( "http://docs.phplivesupport.com/viewarticle.php?aid=76&pid=6&uid=1", @DesktopDir & "\IISandPHPonWin2K.MHT" ) Func _INetGetMHT( $url, $file ) Local $msg = ObjCreate("CDO.Message") If @error Then Return False Local $ado = ObjCreate("ADODB.Stream") If @error Then Return False With $ado .Type = 2 .Charset = "US-ASCII" .Open EndWith $msg.CreateMHTMLBody($url, 0) $msg.DataSource.SaveToObject($ado, "_Stream") FileDelete($file) $ado.SaveToFile($file, 1) $msg = "" $ado = "" Return True EndFunc AutoIt3 Online Help Link to comment Share on other sites More sharing options...
avmir Posted May 2, 2010 Author Share Posted May 2, 2010 danwilliAt first I was delighted - referred to the page you actually preserved. But then primenid script to my task, to my URL - http://abook-club.ru/forum/index.php?showtopic=34175The result remained the same - without the style and images ... Link to comment Share on other sites More sharing options...
DW1 Posted May 2, 2010 Share Posted May 2, 2010 Ah.. now that I see the site, I fully understand the question, sorry. Maybe somebody better with the _IE functions can help. AutoIt3 Online Help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now