C#
using DotNetBrowser; using DotNetBrowser.DOM; using DotNetBrowser.Events; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace DOMGetAttributesSample { class Program { static void Main(string[] args) { using (Browser browser = BrowserFactory.Create()) { ManualResetEvent waitEvent = new ManualResetEvent(false); browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e) { if (e.IsMainFrame) { DOMDocument document = e.Browser.GetDocument(); DOMElement link = document.GetElementById("link"); Dictionary<String, String> attributes = link.Attributes; foreach (var attribute in attributes) { Console.Out.WriteLine(attribute.Key + " = " + attribute.Value); } waitEvent.Set(); } }; browser.LoadHTML("<html><body><a href='#' id='link' title='link title'></a></body></html>"); waitEvent.WaitOne(); } } } }
VB.NET
Imports DotNetBrowser Imports DotNetBrowser.DOM Imports DotNetBrowser.Events Imports System.Threading Module DOMGetAttributesSample Sub Main(ByVal args As String()) Using browser As Browser = BrowserFactory.Create() Dim waitEvent As ManualResetEvent = New ManualResetEvent(False) AddHandler browser.FinishLoadingFrameEvent, sub(ByVal sender As Object, ByVal e As FinishLoadingEventArgs) If e.IsMainFrame Then Dim document As DOMDocument = e.Browser.GetDocument() Dim link As DOMElement = document.GetElementById("link") Dim attributes As Dictionary(Of String, String) = link.Attributes For Each attribute In attributes Console.Out.WriteLine(attribute.Key & " = " & attribute.Value) Next waitEvent.Set() End If End sub browser.LoadHTML("<html><body><a href='#' id='link' title='link title'></a></body></html>") waitEvent.WaitOne() End Using End Sub End Module