?
Solved

Problem with webbrowser component (VB) while saving files automatically

Posted on 2003-11-09
5
Medium Priority
?
5,889 Views
Last Modified: 2007-12-19
I was able to use webbrowser component to access the pages and save them. However, still there is some problem in automatically saving the pages.  

here is the code that i am using
--------------------
Private Sub Form_Load()
   WebBrowser1.Navigate "http://www.msn.com"
   Command3.Caption = "Save pages"
End Sub

Private Sub Command3_Click()
 Dim A(3) As Variant
   A(1) = "laptop"
   A(2) = "pc"
   A(3) = "digital+camera"
 For i = 1 To UBound(A)
   FileName = "http://google.com/search?q=" + A(i)
   WebBrowser1.Navigate FileName
   'WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT
   WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER, "search_" + A(i) + ".html", "whatshouldbehere"

  Next i
End Sub
------------------

When i use 'WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT"  then I am able to save all three pages.
BUT
1) the first file is named using the previous page's name (i.e for laptop page the name is MSN (which was the page displayed before it).
2) Another problem is that it also creates a directory for each file containing objects on that page.

When I use WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER, "search_" + A(i) + ".html", "whatshouldbehere" then the first file shown (here MSN during the form load) is saved three times with different names (using the array elements). Also, even though it says donotprompt user, still I have to press okay to save the file. Only thing is that the name that i have given as the 1rst parameter appears in the "file save dialog box".

Any idea as to what am i doing wrong?
thanks,
Animesh
0
Comment
Question by:sir_animesh
  • 3
5 Comments
 
LVL 5

Accepted Solution

by:
fantasy1001 earned 375 total points
ID: 9711847
I think you should have wait for the webbrowser to finish loading first.

do while not webbrowser1.ready = 4
   doevents
loop

~ fantasy ~
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 9714870
>  1) the first file is named using the previous page's name (i.e for laptop page the name is MSN (which was the page displayed before it).

Possibly due to the pages not loading when you attempt to save them. Use fantasy's suggestion.


>  2) Another problem is that it also creates a directory for each file containing objects on that page.

When you use the "OLECMDID_SAVEAS" option, it's basically the same as going to "File" then "Save As" in IE. It'll save all of the files on the page (from Temp. Internet Files I believe) into a seperate folder and the BASEDIR of all of the links in the saved pages will be pointed to that folder. I'm not aware of any work-around for that.




Do you require only saving the HTML of the page or all files mentioned therein? Such as images/links/etc.
0
 

Expert Comment

by:aanimesh
ID: 9715953
Hi fantasy,

I will try out your suggestion and let you know.

zzzzzooc, I just need to save the html text (without additional characters). Just plain html text that should appear as normal text if i open it in notepad etc.

Can you guys, also let me know how to select a comment as answer. I can't see any radio button alongside the comments or some other mechanism to select a comment.

thanks a lot guys
animesh
0
 

Expert Comment

by:aanimesh
ID: 9717172
fantasy your idea works
but the syntax does not..the right syntax i figured is
---------
Do While WebBrowser1.Busy = True
  Loop
-------------------
 When i use "WebBrowser1.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT" after this wait loop, i get 3 different files (with right content) as i want BUT the each file takes the name of its previous page i.e. file with page content is named as page1.html.

Anyway, since the saveas option does not let me automate the process, i decided to save the file using simple text I/O code
here is the code that i intend to use
------------------------
Open "k:\siva\google_" + A(i) + ".html" For Output As #1
   Print #1, GetCurrentHTML
Close #1
-------------------------
NOw the only question I have it how to populate "GetCurrentHTML" String with the HTML from the document object.
If that works then i will resolve my problem.

Thanks a lot
animesh
0
 

Expert Comment

by:aanimesh
ID: 9719002
hi guys,

well, i found an alternative way to read html page and save it in a file (which means that i do not need to know the answer to my previous post (using webbrowser document object to do it) but it would be interesting for me and many others to see how it can be done.

there is sample VB code available at http://www.zarr.net/vb/download/codedetail.asp?code=257 for a program called Simple Internet File Reader. The program takes a URL and turns it into text output (which it displays on the screen). I am modifying it for my purpose.

Anyway, Fantasy ...your comment was very helpful and i would like to give you credit  (point ) for that ...but can't see the "Accept" icon against any of the comments.
zzzzzoc ..i appreciate your help too....
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question