Solved

Problem with webbrowser component (VB) while saving files automatically

Posted on 2003-11-09
5
5,838 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 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…

740 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