public void HTMLDocumentAsynchronouslyOnLoadTest() { // Initialize an AutoResetEvent var resetEvent = new AutoResetEvent(false); // Initialize an HTML document var document = new HTMLDocument(); var isLoading = false; // Subscribe to the 'OnLoad' event // This event will be fired once the document is fully loaded document.OnLoad += (sender, @event) => { isLoading = true; resetEvent.Set(); }; // Navigate asynchronously at the specified Uri document.Navigate("https://docs.aspose.com/html/net/working-with-documents/creating-a-document/document.html"); // Here the document is not loaded yet Assert.False(isLoading); // Wait 5 seconds for the file to load Assert.True(resetEvent.WaitOne(5000), "Thread works too long, more than 5000 ms"); // Here is the loaded document Assert.True(isLoading); Output.WriteLine("outerHTML = {0}", document.DocumentElement.OuterHTML); }
private static void Main(string[] args) { var htmlDocument = new HTMLDocument(); //htmlDocument.OnLoad += MakeImage; htmlDocument.OnReadyStateChange += MakePDF; htmlDocument.Navigate("http://jv.gilead.org.il/pg/22759-h/"); IsFinished.WaitOne(); htmlDocument.Dispose(); }
public static void EventNavigate() { // ExStart:EventNavigate // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Data(); var document = new HTMLDocument(); // you can subscribe to the event 'OnLoad' document.OnLoad += (sender, @event) => { // manipulate with document here }; document.Navigate(dataDir + "input.html"); // ExEnd:EventNavigate }
public void HTMLDocumentAsynchronouslyOnReadyStateChangeTest() { // Initialize an AutoResetEvent var resetEvent = new AutoResetEvent(false); // Create an instance of an HTML document var document = new HTMLDocument(); // Create a string variable for OuterHTML property reading var outerHTML = string.Empty; // Subscribe to 'ReadyStateChange' event // This event will be fired during the document loading process document.OnReadyStateChange += (sender, @event) => { // Check the value of 'ReadyState' property // This property is representing the status of the document. For detail information please visit https://www.w3schools.com/jsref/prop_doc_readystate.asp if (document.ReadyState == "complete") { // Fill the outerHTML variable by value of loaded document outerHTML = document.DocumentElement.OuterHTML; resetEvent.Set(); } }; // Navigate asynchronously at the specified Uri document.Navigate("https://docs.aspose.com/html/net/working-with-documents/creating-a-document/document.html"); // Here the outerHTML is empty yet Assert.True(string.IsNullOrEmpty(outerHTML)); Output.WriteLine($"outerHTML = {outerHTML}"); // Wait 5 seconds for the file to load Assert.True(resetEvent.WaitOne(5000), "Thread works too long, more than 5000 ms"); // Here the outerHTML is filled Output.WriteLine("outerHTML = {0}", outerHTML); Assert.False(string.IsNullOrEmpty(outerHTML)); Assert.Contains("<body>Hello World!</body>", outerHTML); Assert.True(document.DocumentElement.TagName.ToLower() == "html"); }
public static void Run() { // ExStart:LoadHTMLdocAsyn // The path to the documents directory. string dataDir = RunExamples.GetDataDir_Data(); var document = new HTMLDocument(); // subscribe to the event 'OnReadyStateChange' that will be fired once document is completely loaded document.OnReadyStateChange += (sender, @event) => { if (document.ReadyState == "complete") { // manipulate with document here } }; document.Navigate(dataDir + "input.html"); // ExEnd:LoadHTMLdocAsyn }