copyright 1999 - 2014 by heinz prelle - hannover  - lenbachstraße 42 - www.visual-basic5.de | impressum
'Beispiel: VB .Net - Webseite ansteuern - Links auswerten - InnerText auswerten - Wenn InnerText einem bestimmten Kriterium entspricht den entsprechenden Link ansteuern.
'
Option Explicit On
Option Strict On

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With Me
            .Text = "Webseite ansteuern - Links auswerten - InnerText auswerten - Wenn InnerText einem bestimmten Kriterium entspricht den entsprechenden Link ansteuern"
            .WindowState = FormWindowState.Maximized
        End With
        WebBrowser1.Navigate("http://www.pi-news.net/2010/04/am-1-mai-kapituliert-der-rechtsstaat/")
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _
            Handles WebBrowser1.DocumentCompleted
        Dim GoToUrl As String = String.Empty
        Const LinkDescription As String = "Home"
        Call CompareInnerText(Me.WebBrowser1, LinkDescription, GoToUrl)
        If Not GoToUrl Is String.Empty Then
            Me.Text = GoToUrl
        End If
    End Sub

    Private Success As Boolean = False
    Private Sub CompareInnerText(ByVal wb As WebBrowser, ByVal Description As String, ByRef GoToUrl As String)
        Dim url As String = String.Empty
        If Success Then
            Exit Sub
        End If
        For Each Element As HtmlElement In wb.Document.Links
            If String.Equals(Element.InnerText, Description, StringComparison.OrdinalIgnoreCase) Then
                GoToUrl = Element.GetAttribute("href")
                wb.Navigate(Element.GetAttribute("href"))
                Exit For
            End If
        Next
        Try
        Catch ex As Exception
            '
        End Try
        Success = True
    End Sub

End Class