Beispiel #1
0
 public void TestAsyncHtmlParsing()
 {
     var source = "<html><head><title>My test</title></head><body><p>Some text</p></body></html>";
     var parser = new HtmlParser(source);
     var task = parser.ParseAsync();
     Assert.IsFalse(task.IsCompleted);
     Assert.IsNotNull(parser.Result);
     Assert.IsFalse(task.IsCompleted);
     task.Wait();
     Assert.IsTrue(task.IsCompleted);
     Assert.IsNotNull(parser.Result);
     Assert.AreEqual("My test", parser.Result.Title);
     Assert.AreEqual(1, parser.Result.Body.ChildElementCount);
     Assert.AreEqual("Some text", parser.Result.Body.Children[0].TextContent);
 }
Beispiel #2
0
        static async Task TestAsync()
        {
            Console.WriteLine("Starting async!");
            var sw = Stopwatch.StartNew();
            var parser = new HtmlParser(HtmlFiles.W3C);

            var task = parser.ParseAsync();

            while (!task.IsCompleted)
            {
                await Task.Delay(15);
                Console.WriteLine("{0} | {1} elements", sw.ElapsedMilliseconds, parser.Result.All.Length);
            }

            sw.Stop();
            Console.WriteLine("Done!");
        }