locked
Need Help with .GetAttribute & .SetAttribute RRS feed

  • Question

  • Hello & Thanks ;

    I need to convert Code1  to the same format as Code2 ;

    ie. ,  This format:   If linkElements.Count > 0 Then 

    Into this format: For Each elem As HtmlElement In elems 

    but I keep getting mixed up as to who/what goes where .

    Thanks for your Help...

    Code1:

                  Dim linkElements As HtmlElementCollection =
                   WebBrowser1.Document.GetElementsByTagName("A")
                   Dim LinkIn = linkElements.Cast(Of HtmlElement).FirstOrDefault()
                 If linkElements.Count > 0 Then
                             linkElements = WebBrowser1.Document.GetElementsByTagName("A")
                If LinkIn.GetAttribute("target") = "_blank" Then
                   LinkIn.SetAttribute("target", "_self")
                   MsgBox("linkElements.Count =  " & linkElements.Count)
                   linkElements = WebBrowser1.Document.GetElementsByTagName("A")
            End If
            End If
    		

    Code2:

        If webBrowser1.Document IsNot Nothing Then
            Dim elems As HtmlElementCollection = webBrowser1.Document.GetElementsByTagName("META")
            For Each elem As HtmlElement In elems
                Dim nameStr As String = elem.GetAttribute("name")
    
                If nameStr IsNot Nothing AndAlso nameStr.Length <> 0 Then
                    Dim contentStr As String = elem.GetAttribute("content")
                    MessageBox.Show("Document: " & webBrowser1.Url.ToString() & vbLf & "Description: " + contentStr)
                End If
            Next
        End If


    "All things in moderation, except for love and forgiveness."...vm

    • Moved by litdev Tuesday, September 22, 2020 2:05 PM
    • Moved by Dave PatrickMVP Wednesday, September 23, 2020 10:11 AM
    Friday, August 28, 2020 1:12 AM

All replies