Jump to content

Need Help Saving A Webpage (Internet Explorer)


Go to solution Solved by DW1,

Recommended Posts

Hello,

I got AutoIt to call up a web page and used

Send("{ALT}")
Send("f")
Send("a")

to call up the "Save Webpage" dialog box, but for the life of me I can't access the box. In addition to the direct approach, I tried these lines:

WinActivate("Save Webpage", "")
Send("Testfile")
Send("{ENTER}")

and:

WinActivate("[CLASS:Save Webpage]", "")
Send("Testfile")
Send("{ENTER}")

Neither of them worked to save "Testfile.htm" [the test name for the Webpage I'm trying to save] from the open dialog box.

How do I script it so that AutoIt saves the Webpage? Are there some commands that can access the dialog box, or should I use a different approach entirely?

As the lines above indicate, I just want to save the webpage raw - nothing fancy :)

 

Thanks.

Link to comment
Share on other sites

As pointed out by DanP2, you can easily read the HTML and save the results to a file with the IE functions.

You can also do this with _INetGetSource.

If you need the entire page (pictures, etc) you may want to look in to saving as mht.

Here is an example of saving a page in mht format:

;EXAMPLE:
_INetGetMHT( "http://msdn.microsoft.com/en-us/library/ms526453%28v=exchg.10%29.aspx", "D:\IMessage Interface.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
Link to comment
Share on other sites

Thanks to you both. I did look at  _IEDocReadHTML, but couldn't find a way to save the contents of the variable to a file. My attempts to read it into a Notepad file were, to put it one way, comical.

I should have explained: I'm trying to save the page after using AutoIt to fill in some fields and waiting for the server to return the data asked for. If I use the raw URL, that data won't be there: I need to fill in the forms first. That part, I already figured out. I asked because I couldn't find any IE_... function with "Save" in the title.

Can you point out some way to get the _IEDocReadHTML variable into a saveable file without any fireworks? If so, thanks a lot.  

 

As pointed out by DanP2, you can easily read the HTML and save the results to a file with the IE functions.

You can also do this with _INetGetSource.

If you need the entire page (pictures, etc) you may want to look in to saving as mht.

Here is an example of saving a page in mht format:

;EXAMPLE:
_INetGetMHT( "http://msdn.microsoft.com/en-us/library/ms526453%28v=exchg.10%29.aspx", "D:\IMessage Interface.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
Link to comment
Share on other sites

  • Solution

Sure, here is an example of saving a page after searching for something in google

#include <IE.au3>
Local $oIE = _IECreate("http://www.google.com", 0, 0)
Local $oForm = _IEFormGetCollection($oIE, 0)
Local $oQuery = _IEFormElementGetObjByName($oForm, "q")
_IEFormElementSetValue($oQuery, "AutoIt IE.au3")
_IEFormSubmit($oForm)
While _IEPropertyGet($oIE, "busy")
    Sleep(100)
WEnd
FileWrite(@MyDocumentsDir & '\Results.html', _IEDocReadHTML($oIE))
_IEQuit($oIE)
ShellExecute(@MyDocumentsDir & '\Results.html')

Hope this helps

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...