Page 1 of 2
saving webgadget content as webpage complete
Posted: Fri Apr 02, 2004 4:10 am
by wdurden
Hi all, I am wrestling with a problem someone may have solved already. In Internet Explorer there is a save option to save the browser content as web page complete which captures all of the images etc to local resources. I am trying to solve this with the webgadget. In other words, I load an url and want to save it all to a local resource in one fell swoop without iterating through it capturing all the images, etc. About all I could find was on a visual basic forum where the following one liner apparently does the trick in that environment using the webbrowser control...
webbrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER
How does one go about this with the webgadget in pureBasic if it's possible?
Posted: Fri Apr 02, 2004 9:11 am
by freak
Code: Select all
; Constants for the ExecWB() method of IWebBrowser2
Enumeration 1
#OLECMDID_OPEN
#OLECMDID_NEW
#OLECMDID_SAVE
#OLECMDID_SAVEAS
#OLECMDID_SAVECOPYAS
#OLECMDID_PRINT
#OLECMDID_PRINTPREVIEW
#OLECMDID_PAGESETUP
#OLECMDID_SPELL
#OLECMDID_PROPERTIES
#OLECMDID_CUT
#OLECMDID_COPY
#OLECMDID_PASTE
#OLECMDID_PASTESPECIAL
#OLECMDID_UNDO
#OLECMDID_REDO
#OLECMDID_SELECTALL
#OLECMDID_CLEARSELECTION
#OLECMDID_ZOOM
#OLECMDID_GETZOOMRANGE
#OLECMDID_UPDATECOMMANDS
#OLECMDID_REFRESH
#OLECMDID_STOP
#OLECMDID_HIDETOOLBARS
#OLECMDID_SETPROGRESSMAX
#OLECMDID_SETPROGRESSPOS
#OLECMDID_SETPROGRESSTEXT
#OLECMDID_SETTITLE
#OLECMDID_SETDOWNLOADSTATE
#OLECMDID_STOPDOWNLOAD
EndEnumeration
Enumeration 0
#OLECMDEXECOPT_DODEFAULT
#OLECMDEXECOPT_PROMPTUSER
#OLECMDEXECOPT_DONTPROMPTUSER
#OLECMDEXECOPT_SHOWHELP
EndEnumeration
; -----------------------------------------------------
#WebGadget = 1
#Button = 2
OpenWindow(0, 0, 0, 800, 800, #PB_Window_Screencentered|#PB_Window_SystemMenu, "WebBrowser")
CreateGadgetList(WindowID())
WebGadget(#WebGadget, 10, 40, 780, 750, "www.purebasic.com")
ButtonGadget(#Button, 10, 10, 60, 20, "Save")
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA)
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget And EventGadgetID() = #Button
; Send the Save Command to the WebGadget:
WebObject\ExecWB(#OLECMDID_SAVEAS, #OLECMDEXECOPT_PROMPTUSER, 0, 0)
EndIf
Until Event = #PB_EventCLoseWindow
End
Timo
Posted: Fri Apr 02, 2004 10:53 am
by Fred
Freak is definitely the IWebBrowser2 interface king !

Posted: Fri Apr 02, 2004 11:44 am
by freak
lol, i just repost my original example over and over again and change some constants

freak, that rocks... Now, just one other thing ...
Posted: Fri Apr 02, 2004 2:25 pm
by wdurden
is there a way to save it without the dialog box coming up? The don't prompt option doesn't do what I thought, it puts up a dialog box, it's just the file name is untitled and the default path is more generic (My Documents) instead of the last used... What I am really hoping now is that I can programatically assign a file name and save it without further adoo by clicking the save button in your example... From reviewing forums in other language bases, I am not sure this is a doable option, but it looks like if it can be done, you are the guy to ask!!! Thanks again, your example is super! I just cannot get over the community behind this language and program! There is nothing like it anywhere else!!!!
Posted: Fri Apr 02, 2004 2:30 pm
by freak
i will see what i can patch together tonight...
Posted: Mon Jul 16, 2007 2:03 am
by Seymour Clufley
Hi,
I'm in a similar situation as the OP. I'm trying to write a program that gets a URL from a txt file, then downloads that URL to an mht file.
As a newbie experienced only in Blitz3D, I have to admit I'm out of my depth. There are several examples on these forums but none of them are exactly what I want. I'm posting on this thread because it's the closest. Saving to mht is essential, and I don't want any involvement by the user - the program should run invisibly. Therefore, the separate thread for downloading is also unnecessary and that makes several other examples unsuitable unless I'm going to adapt them drastically.
Here is the code as it is just now:
Code: Select all
Global url$
Global outputfile$
file$="C:\mht instruction.txt"
If ReadFile(0,file$)
urltodownload$=ReadString(0)
outputfile$="C:\mht test.mht"
Else
End
EndIf
Enumeration 1
#OLECMDID_OPEN
#OLECMDID_NEW
#OLECMDID_SAVE
#OLECMDID_SAVEAS
#OLECMDID_SAVECOPYAS
#OLECMDID_PRINT
#OLECMDID_PRINTPREVIEW
#OLECMDID_PAGESETUP
#OLECMDID_SPELL
#OLECMDID_PROPERTIES
#OLECMDID_CUT
#OLECMDID_COPY
#OLECMDID_PASTE
#OLECMDID_PASTESPECIAL
#OLECMDID_UNDO
#OLECMDID_REDO
#OLECMDID_SELECTALL
#OLECMDID_CLEARSELECTION
#OLECMDID_ZOOM
#OLECMDID_GETZOOMRANGE
#OLECMDID_UPDATECOMMANDS
#OLECMDID_REFRESH
#OLECMDID_STOP
#OLECMDID_HIDETOOLBARS
#OLECMDID_SETPROGRESSMAX
#OLECMDID_SETPROGRESSPOS
#OLECMDID_SETPROGRESSTEXT
#OLECMDID_SETTITLE
#OLECMDID_SETDOWNLOADSTATE
#OLECMDID_STOPDOWNLOAD
EndEnumeration
Enumeration 0
#OLECMDEXECOPT_DODEFAULT
#OLECMDEXECOPT_PROMPTUSER
#OLECMDEXECOPT_DONTPROMPTUSER
#OLECMDEXECOPT_SHOWHELP
EndEnumeration
#WebGadget = 1
windownum=OpenWindow(0, 0, 0, 800, 800, "WebBrowser", #PB_Window_Invisible )
CreateGadgetList(windownum)
WebGadget(#WebGadget, 10, 40, 780, 750, url$)
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA)
WebObject\ExecWB(#OLECMDID_SAVEAS, #OLECMDEXECOPT_PROMPTUSER, 0, 0)
That's mostly cobbled together from examples on this forum.
As it is, the program just starts and then closes down and there's no mht file.
However, I suspect that once I've sorted that problem, there'll be another problem:
#OLECMDID_SAVEAS, #OLECMDEXECOPT_PROMPTUSER sounds like it's going to put up the dialogue box for the user to choose a destination file.
As I said, I've found examples on this forum for downloading a webpage but they are incredibly complicated and I don't have a clue what's going on.
If anybody can offer some pointers (or even better, if Freak could "patch something together"!

), I'd be very, very grateful.
All the best,
Seymour.
Posted: Thu Jul 26, 2007 3:18 pm
by Seymour Clufley
Anyone?
Posted: Mon Jul 30, 2007 7:04 pm
by freak
With the 4.10 betas, this is supported by the gadget directly. (through GetGadgetItemText())
Posted: Thu Aug 02, 2007 4:48 pm
by Seymour Clufley
Oh, fantastic. I've seen the command but didn't know it could be used to get an mht file. Can you tell me how?
Posted: Mon Aug 06, 2007 11:08 am
by Seymour Clufley
Does anyone know how to silently download from a URL to a MHT file?
This is fast becoming the bane of my life. All the examples I can find either involve obsolete code or a user prompt, and I really want to download it invisibly.
Please help, anyone.
Posted: Wed Oct 24, 2007 10:04 am
by Kwai chang caine
Hello FREAK
I have try your GREAT code for saving an internet page.
But i have a problem.
I can't save some pages of the web.
For example this :
http://www.ebay.fr
Do you know why ??
Thanks for your answer

Posted: Wed Oct 24, 2007 10:16 am
by Derek
Saves Ok on mine, although when I run the file I have to allow blocked content through but that's normal.
Posted: Wed Oct 24, 2007 3:40 pm
by Kwai chang caine
Thank's DEREK for your quick answer
Can you test this, and save in
MHT
With this option, i have an "error message" and i can't save the page
Code in v4.10
Code: Select all
; Constants for the ExecWB() method of IWebBrowser2
Enumeration 1
#OLECMDID_OPEN
#OLECMDID_NEW
#OLECMDID_SAVE
#OLECMDID_SAVEAS
#OLECMDID_SAVECOPYAS
#OLECMDID_PRINT
#OLECMDID_PRINTPREVIEW
#OLECMDID_PAGESETUP
#OLECMDID_SPELL
#OLECMDID_PROPERTIES
#OLECMDID_CUT
#OLECMDID_COPY
#OLECMDID_PASTE
#OLECMDID_PASTESPECIAL
#OLECMDID_UNDO
#OLECMDID_REDO
#OLECMDID_SELECTALL
#OLECMDID_CLEARSELECTION
#OLECMDID_ZOOM
#OLECMDID_GETZOOMRANGE
#OLECMDID_UPDATECOMMANDS
#OLECMDID_REFRESH
#OLECMDID_STOP
#OLECMDID_HIDETOOLBARS
#OLECMDID_SETPROGRESSMAX
#OLECMDID_SETPROGRESSPOS
#OLECMDID_SETPROGRESSTEXT
#OLECMDID_SETTITLE
#OLECMDID_SETDOWNLOADSTATE
#OLECMDID_STOPDOWNLOAD
EndEnumeration
Enumeration 0
#OLECMDEXECOPT_DODEFAULT
#OLECMDEXECOPT_PROMPTUSER
#OLECMDEXECOPT_DONTPROMPTUSER
#OLECMDEXECOPT_SHOWHELP
EndEnumeration
; -----------------------------------------------------
#WebGadget = 1
#Button = 2
OpenWindow(0, 0, 0, 800, 800, "WebBrowser", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
CreateGadgetList(WindowID(0))
WebGadget(#WebGadget, 10, 40, 780, 750, "http://www.ebay.fr")
ButtonGadget(#Button, 10, 10, 60, 20, "Save")
WebObject.IWebBrowser2 = GetWindowLong_(GadgetID(#WebGadget), #GWL_USERDATA)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget And EventGadget() = #Button
; Send the Save Command to the WebGadget:
WebObject\ExecWB(#OLECMDID_SAVEAS, #OLECMDEXECOPT_PROMPTUSER, 0, 0)
EndIf
Until Event = #PB_Event_CloseWindow
End
Posted: Wed Oct 24, 2007 5:09 pm
by Derek
If I change the extension to MHT then it still saves ok but won't open the page when clicked on, instead it brings up the text that makes the page, still no errors though.
How are you saving as MHT? Are you just changing the extension as I did?