Solved

Problem with webbrowser component (VB) while saving files automatically

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

930 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

12 Experts available now in Live!

Get 1:1 Help Now