hi guys
right now I'm using createDocumentFromUrl to load htmldocument, but is it possible to use URLDownloadToFile and then load the local file into?
thanks
Printable View
hi guys
right now I'm using createDocumentFromUrl to load htmldocument, but is it possible to use URLDownloadToFile and then load the local file into?
thanks
Yes, that would be possible. But why would you want to do that? CreateDocumentFromURL already takes care of the downloading part for you. Anyway, the way to go would be to download the file with URLDownloadToFile, and then point CreateDocumentFromURL to the local file... :)
I tried to point to the local but it the state doesnt go out of loading to complete...
any idea?
In between 'loading' and 'complete' there's also 'interactive'. Some pages may never reach 'complete', but with 'interactive' it may be possible to interact with them... ;)
This is working for me:
VB Code:
Dim x As HTMLDocument Dim y As HTMLDocument Set x = New HTMLDocument Set y = x.createDocumentFromUrl("file://c:/contact.htm", "") Do While y.readyState = "loading" Or y.readyState = "interactive" DoEvents Loop MsgBox y.documentElement.outerHTML Set x = Nothing Set y = Nothing
you can use inet control (Components-> "Microsoft Internet Transfer Control") which is pretty much faster raw access to the web-page html code (also used for simple downloading). inet is less complex then HTML object and there for it will make you program less buggy, and about 40% more pro-active (less cpu).
since it is suitable for simpler pages (not very good with new html 'layers' and 'frames'), you might consider using the HTMLDOCUMENT object (as you've used it before) with needed code-correction.
put those at the very top of your code (global definitions).
Private Const myURL as String = "http://www.google.com"
Dim hStart As HTMLDocument
Dim WithEvents hdoc As HTMLDocument
use set at page_load sub:
Private Sub Form_Load()
Set hStart = New HTMLDocument
End Sub
Now use the proper way:
Private Sub startFetch()
Set hdoc = hStart.createDocumentFromUrl(myURL, vbNullString)
End Sub
loot at the sub list for the hdoc object (at the top of the screen, where you have the combo-boxes of all the objects in your program), select the hdoc_onreadystatechange and fill the sub content like this:
Private Sub hdoc_onreadystatechange()
If (hdoc.readyState = "complete") Then
Text1.Text=hdoc.documentElement.innerText
'or you can use the innerHTML
End If
End Sub
using this proper use with the WithEvents will make your HTML object faster and your program less cpu consuming, since the HTML object is self responsible, and will Jump-An-Event only when time has come,
and buddy- the DoEvents inside a loop don't make your program smarter, since this loop step is done hundreds of times !.
I Hope this would Help you,
since both ways are nice (the inet is much less cpu-consuming),
try both and choose your favorite.
F.Y.I
release the objects by
hdoc.Close
DoEvents
set hdoc=Nothing
DoEvents
this is the proper way to clean-up the HTML object.
sincerely,
Elad Karako
Israel.