本文整理汇总了Python中dominic.DOM类的典型用法代码示例。如果您正苦于以下问题:Python DOM类的具体用法?Python DOM怎么用?Python DOM使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DOM类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_by_attribute_id
def select_by_attribute_id(context):
"selecting by attribute (id)"
dom = DOM(context.html)
(body, ) = dom.find("[id=firstp]")
assert that(body).is_a(Element)
assert that(body.attribute['id']).equals("firstp")
示例2: select_html
def select_html(context):
"selecting html"
dom = DOM(context.html)
html = dom.get("html")
assert that(html).is_a(Element)
assert that(html.attribute['id']).equals("html")
示例3: select_by_id
def select_by_id(context):
"selecting by id"
dom = DOM(context.html)
body = dom.find("#firstp").first()
assert that(body).is_a(Element)
assert that(body.attribute['id']).equals("firstp")
示例4: text_return_the_text_within_element
def text_return_the_text_within_element(context):
"Element().text() returns the text content"
dom = DOM(context.html)
p = dom.find("#the-only-paragraph").first()
assert that(p.text()).equals("the only one in th whole damn thing!?")
示例5: attr_retrieves_each_attribute_by_name
def attr_retrieves_each_attribute_by_name(context):
"attr retrieves attributes each attribute by name"
dom = DOM(context.html)
ul = dom.find("#objects").first()
assert that(ul.attr('id')).equals('objects')
assert that(ul.attr('class')).equals('list no-bullets')
示例6: select_by_class_with_many_classes
def select_by_class_with_many_classes(context):
"selecting by many classes at once"
dom = DOM(context.html)
elements = dom.find("li.stuff.thing")
assert that(elements).the_attribute('tag').equals('li')
assert that(elements[0].attribute['id']).equals('house')
示例7: select_paragraphs
def select_paragraphs(context):
"selecting paragraphs"
dom = DOM(context.html)
paragraphs = dom.find("p")
assert that(paragraphs).is_a(ElementSet)
assert paragraphs.length is 6
示例8: select_by_child
def select_by_child(context):
"selecting by parent > child, mixing many kinds of selectors"
dom = DOM(context.html)
elements = dom.find(
"ul#objects > li.geometry"
)
assert that(elements).in_each('tag').matches(['li', 'li'])
assert that(elements).in_each("attribute['id']").matches(['ball', 'square'])
示例9: select_by_child_complex
def select_by_child_complex(context):
"selecting by parent > child, mixing many kinds of selectors"
dom = DOM(context.html)
elements = dom.find(
"div.ball.dog.square.house.puppet#like-this-one > ul#objects > li.geometry"
)
assert that(elements).in_each('tag').matches(['li', 'li'])
assert that(elements).in_each("attribute['id']").matches(['ball', 'square'])
示例10: select_paragraphs
def select_paragraphs(context):
"selecting paragraphs"
dom = DOM(context.html)
identifiers = ["firstp", "ap", "sndp", "en", "sap", "first"]
paragraphs = dom.find("p")
assert that(dom).is_a(DOM)
assert that(paragraphs).in_each("attribute['id']").matches(identifiers)
示例11: select_by_class
def select_by_class(context):
"selecting by class name"
dom = DOM(context.html)
div = dom.find(".nothiddendiv").first()
assert that(div).is_a(Element)
assert that(div.attribute['id']).equals("nothiddendiv")
assert that(div.attribute['style']).has("height:1px;")
assert that(div.attribute['style']).has("background:white;")
示例12: html_return_the_html_string
def html_return_the_html_string(context):
"Element().html() returns the html string"
dom = DOM(context.html)
p = dom.find("#the-only-paragraph").first()
assert that(p.html()).equals(
'<p id="the-only-paragraph">the only one in th whole damn thing!?</p>'
)
示例13: select_by_attribute_ends_with_with_quotes
def select_by_attribute_ends_with_with_quotes(context):
"selecting attribute that ends with certain value with quotes"
dom = DOM(context.html)
elements = dom.find("ul#packages > li[id$=\"nd\"]")
assert that(elements).in_each("attribute['id']").matches(
[
'java island',
]
)
示例14: first_returns_the_first
def first_returns_the_first(context):
"selecting all childs of some element"
dom = DOM(context.html)
elements = dom.find("#objects li")
p = elements.first()
assert that(p).is_a(Element)
assert that(p.tag).equals("li")
assert that(p.attribute['id']).equals("ball")
assert that(p.text()).equals("to kick")
示例15: last_returns_the_last
def last_returns_the_last(context):
"selecting all childs of some element"
dom = DOM(context.html)
elements = dom.find("#objects li")
p = elements.last()
assert that(p).is_a(Element)
assert that(p.tag).equals("li")
assert that(p.attribute['id']).equals("puppet")
assert that(p.text()).equals("to care with")