本文整理匯總了Python中bs4.dammit.markup方法的典型用法代碼示例。如果您正苦於以下問題:Python dammit.markup方法的具體用法?Python dammit.markup怎麽用?Python dammit.markup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bs4.dammit
的用法示例。
在下文中一共展示了dammit.markup方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_parse_with_soupstrainer
# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import markup [as 別名]
def test_parse_with_soupstrainer(self):
markup = "No<b>Yes</b><a>No<b>Yes <c>Yes</c></b>"
strainer = SoupStrainer("b")
soup = self.soup(markup, parse_only=strainer)
self.assertEqual(soup.encode(), b"<b>Yes</b><b>Yes <c>Yes</c></b>")
示例2: test_smart_quote_substitution
# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import markup [as 別名]
def test_smart_quote_substitution(self):
# MS smart quotes are a common source of frustration, so we
# give them a special test.
quotes = b"\x91\x92foo\x93\x94"
dammit = UnicodeDammit(quotes)
self.assertEqual(self.sub.substitute_html(dammit.markup),
"‘’foo“”")
示例3: test_attribute_name_containing_unicode_characters
# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import markup [as 別名]
def test_attribute_name_containing_unicode_characters(self):
markup = u'<div><a \N{SNOWMAN}="snowman"></a></div>'
self.assertEqual(self.soup(markup).div.encode("utf8"), markup.encode("utf8"))
示例4: test_unicode_input
# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import markup [as 別名]
def test_unicode_input(self):
markup = u"I'm already Unicode! \N{SNOWMAN}"
dammit = UnicodeDammit(markup)
self.assertEqual(dammit.unicode_markup, markup)
示例5: test_smart_quotes_to_unicode
# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import markup [as 別名]
def test_smart_quotes_to_unicode(self):
markup = b"<foo>\x91\x92\x93\x94</foo>"
dammit = UnicodeDammit(markup)
self.assertEqual(
dammit.unicode_markup, u"<foo>\u2018\u2019\u201c\u201d</foo>")
示例6: test_smart_quotes_to_html_entities
# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import markup [as 別名]
def test_smart_quotes_to_html_entities(self):
markup = b"<foo>\x91\x92\x93\x94</foo>"
dammit = UnicodeDammit(markup, smart_quotes_to="html")
self.assertEqual(
dammit.unicode_markup, "<foo>‘’“”</foo>")
示例7: test_smart_quotes_to_ascii
# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import markup [as 別名]
def test_smart_quotes_to_ascii(self):
markup = b"<foo>\x91\x92\x93\x94</foo>"
dammit = UnicodeDammit(markup, smart_quotes_to="ascii")
self.assertEqual(
dammit.unicode_markup, """<foo>''""</foo>""")
示例8: test_smart_quotes_to_xml_entities
# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import markup [as 別名]
def test_smart_quotes_to_xml_entities(self):
markup = b"<foo>\x91\x92\x93\x94</foo>"
dammit = UnicodeDammit(markup, smart_quotes_to="xml")
self.assertEqual(
dammit.unicode_markup, "<foo>‘’“”</foo>")