saving webgadget content as webpage complete
saving webgadget content as webpage complete
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?
webbrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_PROMPTUSER
How does one go about this with the webgadget in pureBasic if it's possible?
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
EndTimo
quidquid Latine dictum sit altum videtur
freak, that rocks... Now, just one other thing ...
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!!!!
-
Seymour Clufley
- Addict

- Posts: 1267
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
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:
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.
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)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"!
All the best,
Seymour.
-
Seymour Clufley
- Addict

- Posts: 1267
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
-
Seymour Clufley
- Addict

- Posts: 1267
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
- Kwai chang caine
- Always Here

- Posts: 5530
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
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
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
The happiness is a road...Not a destination
- Kwai chang caine
- Always Here

- Posts: 5530
- Joined: Sun Nov 05, 2006 11:42 pm
- Location: Lyon - France
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
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
The happiness is a road...Not a destination


