saving webgadget content as webpage complete

Everything else that doesn't fall into one of the other PB categories.
wdurden
User
User
Posts: 13
Joined: Mon Feb 23, 2004 3:29 am

saving webgadget content as webpage complete

Post 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?
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Fred
Administrator
Administrator
Posts: 18409
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Freak is definitely the IWebBrowser2 interface king ! :wink:
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

lol, i just repost my original example over and over again and change some constants :P
quidquid Latine dictum sit altum videtur
wdurden
User
User
Posts: 13
Joined: Mon Feb 23, 2004 3:29 am

freak, that rocks... Now, just one other thing ...

Post 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!!!!
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

i will see what i can patch together tonight...
quidquid Latine dictum sit altum videtur
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post 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.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Anyone?
freak
PureBasic Team
PureBasic Team
Posts: 5950
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

With the 4.10 betas, this is supported by the gadget directly. (through GetGadgetItemText())
quidquid Latine dictum sit altum videtur
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post 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?
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5530
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post 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 8)
ImageThe happiness is a road...
Not a destination
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Saves Ok on mine, although when I run the file I have to allow blocked content through but that's normal.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5530
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post 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
ImageThe happiness is a road...
Not a destination
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post 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?
Post Reply