Jump to content
Sign in to follow this  
trickytroy

how do i Save an html file

Recommended Posts

Hi, i'm currently working on a web browser and i was wonderring if any body knew how i could use the Filesave dialog func to save theh current webpage i'm on.

#include <GuiConstants.au3>

;Creates the parent gui
$gui = GUICreate("Troyzilla 1.0", @DesktopWidth, @DesktopHeight, -1, -1, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_MAXIMIZE)
    $back = GUICtrlCreateButton("Back", 10, 20, 40, 30,  $BS_BITMAP)
    $forward = GUICtrlCreateButton("Forward", 55, 20, 40, 30, $BS_BITMAP)
    $refresh = GUICtrlCreateButton("Refresh", 100, 20, 40, 30, $BS_BITMAP)
    $GO = GUICtrlCreateButton("GO", 810, 20, 50, 30, $BS_BITMAP)
    $Combo_5 = GUICtrlCreateCombo("http://www.google.com", 150, 25, 640, 21, $GUI_DEFBUTTON)
    $Progress_6 = GUICtrlCreateProgress(1000, 920, 100, 15)
    $Date_8 = GUICtrlCreateDate("Date7", 20, 915, 200, 20)
    $pic = GUICtrlCreatePic("images\troyzilla.jpg", 890, 5, 85, 53)
    $filemenu = GUICtrlCreateMenu ("&File")
    $fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
        GUICtrlSetState(-1,$GUI_DEFBUTTON)
    
    $helpmenu = GUICtrlCreateMenu ("Help")
    $saveitem = GUICtrlCreateMenuitem ("Save",$filemenu)
        GUICtrlSetState(-1, $GUI_DEFBUTTON)
    
    $infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)
    $exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
    $recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1)
    $separator1 = GUICtrlCreateMenuitem ("",$filemenu,2); create a separator line
    $viewmenu = GUICtrlCreateMenu("View",-1,1)  
    $viewfavitem = GUICtrlCreateMenuitem ("Favorites",$viewmenu)

    GUICtrlSetImage ( $back, "images\back.bmp")
    GUICtrlSetImage ( $Forward, "images\forward.bmp")
    GUICtrlSetImage ( $refresh, "images\refresh.bmp")
    GUICtrlSetImage ( $GO, "images\go.bmp")
    
    GUISetState( @SW_MAXIMIZE )

    $info = GUICreate("About Troyzilla", 290, 382,(@DesktopWidth-290)/2, (@DesktopHeight-382)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE)
        $OK = GuiCtrlCreateButton("OK", 80, 330, 120, 40)
        $Pic_2 = GuiCtrlCreatePic("images/info.jpg", 0, 0, 290, 310)
    GUISetState( @SW_HIDE, $info )  
    


;creates the child gui that the dll will be held in.
$internetgui = GUICreate("", @DesktopWidth -15, @DesktopHeight - 190, 3, 78, $WS_CHILD + $WS_BORDER, "", $gui)
    GUISetState()

;opens dll then calls it.
$dll = DllOpen("cwebpage.dll")
    DllCall($dll, "long", "EmbedBrowserObject", "hwnd", $internetgui)
    DllCall($dll, "long", "DisplayHTMLPage", "hwnd", $internetgui, "str", "http://www.google.com")



While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE; states that if the close button is it hte script will exit
            If WinActive( $info ) Then 
                GuiSetState(@SW_HIDE, $info)
            Else
                Exit
            EndIf
                
        Case $msg = $GO 
            DllCall($dll, "long", "DisplayHTMLPage", "hwnd", $internetgui, "str", GUICtrlRead($Combo_5)); tells the dll to go to the web page thats in the combobox
        
        Case  $msg = $back 
            DLLCall($dll,"none","DoPageAction","hwnd",$internetgui,"int", 0)
        
        Case $msg = $forward
            DLLCall($dll,"none","DoPageAction","hwnd",$internetgui,"int", 1)
        
        Case $msg = $refresh 
            DLLCall($dll,"none","DoPageAction","hwnd",$internetgui,"int", 4)
        
        Case $msg = $exititem 
            Exit
        
        Case $msg = $OK 
            GUISetState( @SW_HIDE, $info )  
    
        Case $msg = $fileitem 
            $file = FileOpenDialog("Open","C:","HTML (*.html;*.htm)")
            If @error <> 1 Then GUICtrlCreateMenuitem ($file ,$recentfilesmenu)
            If $msg = $fileitem Then DllCall($dll, "long", "DisplayHTMLPage", "hwnd", $internetgui, "str", $file)
        
        Case $msg = $saveitem
            $save = FileSaveDialog ("Save", @DesktopDir, "Html (*.html)", 3, "gfhf" )
        
        Case $msg = $infoitem               
            GuiSetState(@SW_SHOW, $info)
                    
        EndSelect
    WEnd
Exit

[quote]Randy:This is for what?! Arresting me for what?! I'm not allowed to stand up for myself?! I thought this was America! Huh? Isn't this America?! I'm sorry! I thought this was America![/quote]

Share this post


Link to post
Share on other sites

Something like...

$saveto = FileOpenDialog("Choose a file", "C:\", "Files (*.txt;*.html)", 8 )
If @error Then
   MsgBox(4096,"","No File(s) chosen")
Else
   InetGet(GUICtrlRead($Combo_5),$saveto)
EndIf

Not tested.

Edit: Ofcourse the above only reads whats in the combo box, not what webpage you may or may not be viewing.

Edited by Burrup

qq

Share this post


Link to post
Share on other sites

If you just want it to save, and you don't need the stupid file dialog, you can say:

InetGet(TheURLofTheSite, AFilenameYouSaveItAs)

J


If I am too verbose, just say so. You don't need to run on and on.

Share this post


Link to post
Share on other sites

Naa - You got to go to the URL address and snap out the contense - I don't know how to do this in autoit but here's an example from another language...

You need these functions:

"InternetOpen", "void, str, 32u, str, str, 32u", "wininet"

Register the Windows OS function InternetConnect(). It connects to

a server so that we can subsequently call other WININET functions

to give it commands (such as telling it to send us some web page).

It returns a "server handle" that we need to pass to other WININET

functions, or a 0 if an error.

"InternetConnect", "void, void, str, 32u, str, str, 32u, 32u, 32u", "wininet"

Register the Windows OS function HttpOpenRequest(). It initializes

an HTTP request and returns a handle to that request, or a 0 if an error.

"HttpOpenRequest", "void, void, str, str, str, str, str, 32u, 32u", "wininet"

Register the Windows OS function HttpSendRequest(). It sends an initialized HTTP request and returns 1 if successful or a 0 if an error.

"HttpSendRequest", "32u, void, str, 32u, void, 32u", "wininet"

Register the Windows OS function InternetCloseHandle(). It closes

handles returned by the above functions, when you're done.

"InternetCloseHandle", "32u, void", "wininet"

Register the Windows OS function HttpQueryInfo(), callable as HttpQueryFileSize, to easily query a file's size.

FUNCDEF("HttpQueryFileSize", "32u, void, 32u, str[33] stor, 32u * dual, void", "wininet", "HttpQueryInfo")

Register the Windows OS function InternetReadFile() to download a file.

"InternetReadFile", "32u, void, void, 32u, 32u * stor", "wininet"

Register the Windows OS function GlobalAlloc() to allocate memory.

"GlobalAlloc", "void, 32u, 32u", "kernel32"

Register the Windows OS function GlobalFree() to free memory.

"GlobalFree", "void, void", "kernel32"

and then something like this:

hSession = InternetOpen("My test", 0, , , 0)

hConnect = InternetConnect(hSession, "www.microsoft.com", , "", "", 3)

hHttpFile = HttpOpenRequest(hConnect, "GET", "/MSDN/MSDNINFO/", "HTTP/1.0", , , 67108864)

err = HttpSendRequest(hHttpFile)

bufsize = 33

err = HttpQueryFileSize(hHttpFile, 5, buf, bufsize)

buf = GlobalAlloc(, bufsize)

err = InternetReadFile(hHttpFile, buf, bufsize, dwBytesRead)

GlobalFree(buf)

Close all of the Internet handles.

InternetCloseHandle(hHttpFile)

InternetCloseHandle(hConnect)

InternetCloseHandle(hSession)

This example is from an old guru and friend of mine - Jeff Glatt the CWebPage.dll programmer that knows all about URL that is to know...

KjActive :(

Edited by kjactive

Share this post


Link to post
Share on other sites

Naa - You got to go to the URL address and snap out the contense - I don't know how to do this in autoit but here's an example from another language...

...very long story...

KjActive  :(

<{POST_SNAPBACK}>

This is shorter:

$URL="http://www.AutoItScript.com"

$httpObj = ObjCreate("winhttp.winhttprequest.5.1")
$httpObj.open("GET",$URL)
$httpObj.send()

$HTMLSource = $httpObj.Responsetext

$FileName=FileSaveDialog("Save HTML","C:\","HTML Files (*.htm")

FileWrite($FileName,$HTMLSource)

It will save only the HTML code of the current frame however, not the images and other nifty things people put on those web pages.

Regards,

-Sven

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...