當前位置: 首頁>>代碼示例>>Python>>正文


Python html.parse_html方法代碼示例

本文整理匯總了Python中django.test.html.parse_html方法的典型用法代碼示例。如果您正苦於以下問題:Python html.parse_html方法的具體用法?Python html.parse_html怎麽用?Python html.parse_html使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.test.html的用法示例。


在下文中一共展示了html.parse_html方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_self_closing_tags

# 需要導入模塊: from django.test import html [as 別名]
# 或者: from django.test.html import parse_html [as 別名]
def test_self_closing_tags(self):
        self_closing_tags = (
            'br', 'hr', 'input', 'img', 'meta', 'spacer', 'link', 'frame',
            'base', 'col',
        )
        for tag in self_closing_tags:
            dom = parse_html('<p>Hello <%s> world</p>' % tag)
            self.assertEqual(len(dom.children), 3)
            self.assertEqual(dom[0], 'Hello')
            self.assertEqual(dom[1].name, tag)
            self.assertEqual(dom[2], 'world')

            dom = parse_html('<p>Hello <%s /> world</p>' % tag)
            self.assertEqual(len(dom.children), 3)
            self.assertEqual(dom[0], 'Hello')
            self.assertEqual(dom[1].name, tag)
            self.assertEqual(dom[2], 'world') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:19,代碼來源:tests.py

示例2: test_html_contain

# 需要導入模塊: from django.test import html [as 別名]
# 或者: from django.test.html import parse_html [as 別名]
def test_html_contain(self):
        # equal html contains each other
        dom1 = parse_html('<p>foo')
        dom2 = parse_html('<p>foo</p>')
        self.assertIn(dom1, dom2)
        self.assertIn(dom2, dom1)

        dom2 = parse_html('<div><p>foo</p></div>')
        self.assertIn(dom1, dom2)
        self.assertNotIn(dom2, dom1)

        self.assertNotIn('<p>foo</p>', dom2)
        self.assertIn('foo', dom2)

        # when a root element is used ...
        dom1 = parse_html('<p>foo</p><p>bar</p>')
        dom2 = parse_html('<p>foo</p><p>bar</p>')
        self.assertIn(dom1, dom2)
        dom1 = parse_html('<p>foo</p>')
        self.assertIn(dom1, dom2)
        dom1 = parse_html('<p>bar</p>')
        self.assertIn(dom1, dom2)
        dom1 = parse_html('<div><p>foo</p><p>bar</p></div>')
        self.assertIn(dom2, dom1) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:26,代碼來源:tests.py

示例3: assert_and_parse_html

# 需要導入模塊: from django.test import html [as 別名]
# 或者: from django.test.html import parse_html [as 別名]
def assert_and_parse_html(self, html, user_msg, msg):
    try:
        dom = parse_html(html)
    except HTMLParseError as e:
        standardMsg = '%s\n%s' % (msg, e.msg)
        self.fail(self._formatMessage(user_msg, standardMsg))
    return dom 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:9,代碼來源:testcases.py

示例4: assert_and_parse_html

# 需要導入模塊: from django.test import html [as 別名]
# 或者: from django.test.html import parse_html [as 別名]
def assert_and_parse_html(self, html, user_msg, msg):
    try:
        dom = parse_html(html)
    except HTMLParseError as e:
        standardMsg = '%s\n%s' % (msg, e)
        self.fail(self._formatMessage(user_msg, standardMsg))
    return dom 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:9,代碼來源:testcases.py

示例5: test_html_parser

# 需要導入模塊: from django.test import html [as 別名]
# 或者: from django.test.html import parse_html [as 別名]
def test_html_parser(self):
        element = parse_html('<div><p>Hello</p></div>')
        self.assertEqual(len(element.children), 1)
        self.assertEqual(element.children[0].name, 'p')
        self.assertEqual(element.children[0].children[0], 'Hello')

        parse_html('<p>')
        parse_html('<p attr>')
        dom = parse_html('<p>foo')
        self.assertEqual(len(dom.children), 1)
        self.assertEqual(dom.name, 'p')
        self.assertEqual(dom[0], 'foo') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:14,代碼來源:tests.py

示例6: test_parse_html_in_script

# 需要導入模塊: from django.test import html [as 別名]
# 或者: from django.test.html import parse_html [as 別名]
def test_parse_html_in_script(self):
        parse_html('<script>var a = "<p" + ">";</script>')
        parse_html('''
            <script>
            var js_sha_link='<p>***</p>';
            </script>
        ''')

        # script content will be parsed to text
        dom = parse_html('''
            <script><p>foo</p> '</scr'+'ipt>' <span>bar</span></script>
        ''')
        self.assertEqual(len(dom.children), 1)
        self.assertEqual(dom.children[0], "<p>foo</p> '</scr'+'ipt>' <span>bar</span>") 
開發者ID:nesdis,項目名稱:djongo,代碼行數:16,代碼來源:tests.py

示例7: test_count

# 需要導入模塊: from django.test import html [as 別名]
# 或者: from django.test.html import parse_html [as 別名]
def test_count(self):
        # equal html contains each other one time
        dom1 = parse_html('<p>foo')
        dom2 = parse_html('<p>foo</p>')
        self.assertEqual(dom1.count(dom2), 1)
        self.assertEqual(dom2.count(dom1), 1)

        dom2 = parse_html('<p>foo</p><p>bar</p>')
        self.assertEqual(dom2.count(dom1), 1)

        dom2 = parse_html('<p>foo foo</p><p>foo</p>')
        self.assertEqual(dom2.count('foo'), 3)

        dom2 = parse_html('<p class="bar">foo</p>')
        self.assertEqual(dom2.count('bar'), 0)
        self.assertEqual(dom2.count('class'), 0)
        self.assertEqual(dom2.count('p'), 0)
        self.assertEqual(dom2.count('o'), 2)

        dom2 = parse_html('<p>foo</p><p>foo</p>')
        self.assertEqual(dom2.count(dom1), 2)

        dom2 = parse_html('<div><p>foo<input type=""></p><p>foo</p></div>')
        self.assertEqual(dom2.count(dom1), 1)

        dom2 = parse_html('<div><div><p>foo</p></div></div>')
        self.assertEqual(dom2.count(dom1), 1)

        dom2 = parse_html('<p>foo<p>foo</p></p>')
        self.assertEqual(dom2.count(dom1), 1)

        dom2 = parse_html('<p>foo<p>bar</p></p>')
        self.assertEqual(dom2.count(dom1), 0)

        # html with a root element contains the same html with no root element
        dom1 = parse_html('<p>foo</p><p>bar</p>')
        dom2 = parse_html('<div><p>foo</p><p>bar</p></div>')
        self.assertEqual(dom2.count(dom1), 1) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:40,代碼來源:tests.py


注:本文中的django.test.html.parse_html方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。