Solved

Problem with webbrowser component (VB) while saving files automatically

Posted on 2003-11-09
5
5,798 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 125 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now