Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem with webbrowser component (VB) while saving files automatically

Posted on 2003-11-09
5
Medium Priority
?
5,882 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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