Пример #1
0
        public void HandlesCommentsInTable()
        {
            string   html = "<table><tr><td>text</td><!-- Comment --></tr></table>";
            Document node = Dcsoup.ParseBodyFragment(html);

            Assert.AreEqual("<html><head></head><body><table><tbody><tr><td>text</td><!-- Comment --></tr></tbody></table></body></html>", TextUtil.StripNewlines(node.OuterHtml));
        }
Пример #2
0
        public void ParsesBodyFragment()
        {
            string   h   = "<!-- comment --><p><a href='foo'>One</a></p>";
            Document doc = Dcsoup.ParseBodyFragment(h, "http://example.com");

            Assert.AreEqual("<body><!-- comment --><p><a href=\"foo\">One</a></p></body>", TextUtil.StripNewlines(doc.Body.OuterHtml));
            Assert.AreEqual("http://example.com/foo", doc.Select("a").First.AbsUrl("href"));
        }
Пример #3
0
        public void HandlesUnknownInlineTags()
        {
            string   h    = "<p><cust>Test</cust></p><p><cust><cust>Test</cust></cust></p>";
            Document doc  = Dcsoup.ParseBodyFragment(h);
            string   @out = doc.Body.Html;

            Assert.AreEqual(h, TextUtil.StripNewlines(@out));
        }
Пример #4
0
        static void extractTables(String html)
        {
            Document doc = Dcsoup.ParseBodyFragment(html, "");

            App.dates  = new List <DateTime>();
            App.labs   = new List <string>();
            App.sports = new List <string>();

            System.Diagnostics.Debug.WriteLine("Dates:");
            Supremes.Nodes.Element table = doc.Select("body > div:nth-child(2)").First;
            if (table != null)
            {
                string[] pairs = table.Text.Split(';');
                foreach (string s in pairs)
                {
                    if (s != "" && s != null)
                    {
                        int i = Convert.ToInt16(s.Split(':').First());
                        App.dates.Add(DateTime.ParseExact(s.Split(':').Last(), "yyyy-MM-dd", CultureInfo.InvariantCulture));
                        System.Diagnostics.Debug.WriteLine(s);
                    }
                }
            }


            System.Diagnostics.Debug.WriteLine("Labs:");
            table = doc.Select("body > div:nth-child(3)").First;
            if (table != null)
            {
                string[] pairs = table.Text.Split(';');
                foreach (string s in pairs)
                {
                    if (s != "" && s != null)
                    {
                        int i = Convert.ToInt16(s.Split(':').First());
                        App.labs.Add(s.Split(':').Last());
                        System.Diagnostics.Debug.WriteLine(s);
                    }
                }
            }


            System.Diagnostics.Debug.WriteLine("Sports:");
            table = doc.Select("body > div:nth-child(4)").First;
            if (table != null)
            {
                string[] pairs = table.Text.Split(';');
                foreach (string s in pairs)
                {
                    if (s != "" && s != null)
                    {
                        int i = Convert.ToInt16(s.Split(':').First());
                        App.sports.Add(s.Split(':').Last());
                        System.Diagnostics.Debug.WriteLine(s);
                    }
                }
            }
        }
Пример #5
0
        public void HandlesQuotesInCommentsInScripts()
        {
            string html = "<script>\n" +
                          "  <!--\n" +
                          "    document.write('</scr' + 'ipt>');\n" +
                          "  // -->\n" +
                          "</script>";
            Document node = Dcsoup.ParseBodyFragment(html);

            Assert.AreEqual("<script>\n" +
                            "  <!--\n" +
                            "    document.write('</scr' + 'ipt>');\n" +
                            "  // -->\n" +
                            "</script>", node.Body.Html);
        }
Пример #6
0
        static void extratMarks(String html)
        {
            Document doc = Dcsoup.ParseBodyFragment(html, "");

            User currentUser = new User(false);

            int Column = 0;

            for (int i = 1; ; i++)
            {
                Supremes.Nodes.Element table = doc.Select("body > div.content > div.scrolling-content > table > tbody > tr:nth-child(" + i + ")").First;

                if (table == null)
                {
                    break;
                }


                Elements inputElements = table.GetElementsByTag("td");
                foreach (Supremes.Nodes.Element inputElement in inputElements)
                {
                    if (Column == 0)
                    {
                        currentUser      = new User(true);
                        currentUser.name = inputElement.Text;
                        System.Diagnostics.Debug.WriteLine(inputElement.Text);
                        Column++;
                    }
                    else if (Column == 1)
                    {
                        currentUser.eta = Convert.ToInt16(inputElement.Text);
                        Column++;
                    }
                    else if (Column == 2)
                    {
                        currentUser.lab = Convert.ToInt32(inputElement.Attr("value"));
                        Column++;
                    }
                    else if (Column == 3)
                    {
                        if (Convert.ToInt32(inputElement.Attr("value")) == 1)
                        {
                            currentUser.presences[0] = true;
                        }
                        else
                        {
                            currentUser.presences[0] = false;
                        }

                        Column++;
                    }
                    else if (Column == 4)
                    {
                        currentUser.sports[0] = Convert.ToInt32(inputElement.Attr("value"));
                        Column++;
                    }
                    else if (Column == 5)
                    {
                        if (Convert.ToInt32(inputElement.Attr("value")) == 1)
                        {
                            currentUser.presences[1] = true;
                        }
                        else
                        {
                            currentUser.presences[1] = false;
                        }

                        Column++;
                    }
                    else if (Column == 6)
                    {
                        currentUser.sports[1] = Convert.ToInt32(inputElement.Attr("value"));
                        Column++;
                    }
                    else if (Column == 7)
                    {
                        if (Convert.ToInt32(inputElement.Attr("value")) == 1)
                        {
                            currentUser.presences[2] = true;
                        }
                        else
                        {
                            currentUser.presences[2] = false;
                        }

                        Column++;
                    }
                    else if (Column == 8)
                    {
                        currentUser.sports[2] = Convert.ToInt32(inputElement.Attr("value"));
                        Column++;
                    }
                    else if (Column == 9)
                    {
                        if (Convert.ToInt32(inputElement.Attr("value")) == 1)
                        {
                            currentUser.presences[3] = true;
                        }
                        else
                        {
                            currentUser.presences[3] = false;
                        }

                        Column++;
                    }
                    else if (Column == 10)
                    {
                        currentUser.sports[3] = Convert.ToInt32(inputElement.Attr("value"));
                        Column = 0;
                    }
                }
            }
        }