Need Help with .GetAttribute & .SetAttribute

  • Thread starter Thread starter vmars316
  • Start date Start date
V

vmars316

Guest
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

Continue reading...
 

Similar threads

Back
Top