Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

webbrowser help

Status
Not open for further replies.

99mel

Programmer
Oct 18, 1999
379
GB
Hi all,

I'm wanting to navigate through a web page, automatically picking up specific links that I want and navigating to them. How would i go about this?

I'm using: wb.Navigate (the link)

Really, i'm just wanting to select all the text in a webbrowser and then I can manipulate this text in my code.

Thanks for any help!

Mel

 
You need to get into the DHTML object model.
Here is a sample of what I use to locate a <A HREF...> with specific text and click on it
Code:
Dim objElements     As Object
Dim objElement      As Object
Set objElements = Document.body.All ' Document has wb.document
For I = 0 To objElements.length - 1
    Set objElement = objElements(I)
    If LCase(objElement.tagName) = &quot;a&quot; Then
        If LCase(strElementValue) = Left(LCase(objElement.innerText), Len(strElementValue)) Then
            objElements(I).Click ' Navigate to
            Exit For
        End If
    End If
Next
Give yourself about two weeks to know what you are doing and where to look. Start at using the webbrowser. I use a lot. I just started two weeks ago,
 
thanks for that, at the moment i'm just hardcoding which links are which. Will implement that later on.

I have a problem with navigating my webbrowser! I have the following

WB.Navigate &quot;WB.ExecWB OLECMDID_SELECTALL, OLECMDEXECOPT_DONTPROMPTUSER
WB.ExecWB OLECMDID_COPY, OLECMDEXECOPT_DONTPROMPTUSER
CBtxt = Clipboard.GetText

CBtxt contains the previous web address which was used. Not this one! I have tried WB.Refresh after the Navigate command but to no avail. When i step through it CBtxt contains the correct webpage (webpage data) because the webbrowser is correctly updated to the new webpage. When i run the code (not stepping through), CBtxt still contains the previous one.

Any help is much appreciated!

Mel
 
Navigatye just starts the asynchronus process. I wait for
WebBrowser.Document_Complete.

Code:
Public Sub DocumentComplete(ByVal pDisp As Object, URL As Variant)
    Dim strEvent        As String
    strEvent = &quot; DocumentComplete=&quot;
    Dim objDoc          As HTMLDocument
    Dim objElements     As Object
    Dim objElement      As Object
    Dim strBody As String
    ' Process if whole page is done not just a frame
    If Not (pDisp Is mobjWeb.Object) Then Exit Sub
    
    '*****
    '* Reday State must be interactive or complete
    '*****
    Select Case mobjWeb.ReadyState
    Case READYSTATE_INTERACTIVE, READYSTATE_COMPLETE
    Case Else
        Exit Sub
    End Select
    Set mobjDocument = mobjWeb.Document
    Do
        With mobjWeb
            
            Set objDoc = mobjWeb.Document
            If Err.Number <> 0 Then Exit Do
            If objDoc Is Nothing Then Exit Do
    
            '*****
            '* META http-equiv=&quot;Refresh&quot; BYPASS REDIRECTION
            '*****
            Set objElements = objDoc.getElementsByTagName(&quot;Meta&quot;)
            If Err.Number <> 0 Then Exit Do
            If objElements Is Nothing Then Exit Do
            For Each objElement In objElements
                If LCase(objElement.httpEquiv) = &quot;refresh&quot; Then Exit Do
            Next
            If Err.Number <> 0 Then Exit Do
    
            '*****
            '* CallByName Page Processor
            '*****
            Dim strDownLoad     As String
            strDownLoad = mstrDownload
            mstrDownload = &quot;&quot;
            If Len(strDownLoad) > 0 Then
                CallByName Me, strDownLoad, VbMethod
            End If
        End With
    Exit Do: Loop
    If Err <> 0 Then MsgBox Err.Description & vbCrLf & strEvent: Exit Sub
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top