Ejemplo n.º 1
0
        public void Example_ParseLinks()
        {
            var html = @"<html>  <body>  <script>alert('xss');</script>
                    <a href=""http://www.google.com/"">Google</a>
                    <a href=""http://www.yahoo.com/"">Yahoo</a>  </body>  </html>";

            using (var reader = new HtmlReader(html))
            {
                var urls = reader
                           .OfType <HtmlStartTag>()
                           .Where(t => t.Value == "a")
                           .Select(t => t["href"])
                           .ToArray();

                Assert.Equal(new string[]
                {
                    "http://www.google.com/",
                    "http://www.yahoo.com/"
                }
                             , urls);
            }
        }