本文整理汇总了Python中dominic.DOM.html方法的典型用法代码示例。如果您正苦于以下问题:Python DOM.html方法的具体用法?Python DOM.html怎么用?Python DOM.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dominic.DOM
的用法示例。
在下文中一共展示了DOM.html方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: html_modifies_the_html_within_element
# 需要导入模块: from dominic import DOM [as 别名]
# 或者: from dominic.DOM import html [as 别名]
def html_modifies_the_html_within_element(conhtml):
"Element().html('new html') modifies the html string"
dom = DOM(
'<div class="drinks">\n'
' <h1 id="header">I like marguerita!</h1>\n'
'</div>'
)
h1 = dom.find("div.drinks h1").first()
assert that(h1.html()).equals('<h1 id="header">I like marguerita!</h1>')
h1.html('<strong>Yeah, whiskey is much better!</strong>')
assert that(h1.html()).equals('<strong>Yeah, whiskey is much better!</strong>')
assert that(h1.text()).equals('Yeah, whiskey is much better!')
assert that(dom.html()).equals(
'<div class="drinks">\n'
' <strong>Yeah, whiskey is much better!</strong>\n'
'</div>'
)
示例2: text_modifies_the_text_within_element
# 需要导入模块: from dominic import DOM [as 别名]
# 或者: from dominic.DOM import html [as 别名]
def text_modifies_the_text_within_element(context):
"Element().text('new text') modifies the text content"
dom = DOM(
'<div class="drinks">\n'
' <h1 id="header">I like piña colada!</h1>\n'
'</div>'
)
h1 = dom.find("div.drinks h1").first()
assert that(h1.text()).equals("I like piña colada!")
h1.text('Do you like vodka?')
assert that(h1.text()).equals("Do you like vodka?")
assert that(h1.html()).equals('<h1 id="header">Do you like vodka?</h1>')
assert that(dom.html()).equals(
'<div class="drinks">\n'
' <h1 id="header">Do you like vodka?</h1>\n'
'</div>'
)