Results 1 to 5 of 5

Thread: alternative to createDocumentFromUrl

Hybrid View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160

    alternative to createDocumentFromUrl

    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

  2. #2
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: alternative to createDocumentFromUrl

    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...
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    160

    Re: alternative to createDocumentFromUrl

    I tried to point to the local but it the state doesnt go out of loading to complete...

    any idea?

  4. #4
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: alternative to createDocumentFromUrl

    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:
    1. Dim x As HTMLDocument
    2. Dim y As HTMLDocument
    3. Set x = New HTMLDocument
    4.  
    5. Set y = x.createDocumentFromUrl("file://c:/contact.htm", "")
    6.  
    7. Do While y.readyState = "loading" Or y.readyState = "interactive"
    8.     DoEvents
    9. Loop
    10.  
    11. MsgBox y.documentElement.outerHTML
    12.  
    13. Set x = Nothing
    14. Set y = Nothing
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  5. #5
    New Member
    Join Date
    Sep 2009
    Posts
    4

    yet again- createDocumentFromUrl

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width