#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    52
    Rep Power
    14

    [VB6] parsing contents of web page


    Hi.

    Posting for a friend. I don't use VB6, so I hope that I type everything correctly.

    He's got a WebBrowser object. As I understand it, if he sets WebBrowser1.Navigate to be a URL, the WebBrowser object will go to the URL in question.

    If the URL spits back only one word, such as a name, how can that text be acccessed?

    (The text has no HTML formatting. It is simply Mark or Ernie.)

    Is there a property such as WebBrowser.HTMLPageText or similar?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    52
    Rep Power
    14
    Found this site:

    http://www.tek-tips.com/viewthread.cfm?qid=832833

    Can anyone confirm that

    StringVariable = WebBrowser1.Document.body.innerText
    may do the trick?
  4. #3
  5. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    From what I recall that looks right.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    52
    Rep Power
    14
    So my friend is getting VB run-time error #91 at the following statement:

    var = WebBrowser1.Document.body.innertext


    The WebBrowser1 object should receive a simple 8 bytes from the webpage that it visits.

    Any ideas what causes this error with this object?
  8. #5
  9. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    Stick a DoEvents after the navigate, before you reference the browser...

    Code:
    Private Sub CommandButton1_Click()
        Me.WebBrowser1.Navigate "http://medialint.com"
        Do
            DoEvents
        Loop While Me.WebBrowser1.ReadyState <> READYSTATE_COMPLETE
        MsgBox Me.WebBrowser1.Document.body.innertext
    End Sub
    I tested this in Excel, got the same error until I added the test. Initially it seemed DoEvents would do it but testing the readystate seemed more reliable
    Last edited by medialint; May 30th, 2012 at 02:20 PM.
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

IMN logo majestic logo threadwatch logo seochat tools logo