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


Python DOM.find方法代碼示例

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


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

示例1: select_parent_element

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
def select_parent_element(context):
    "selecting by parent element"
    dom = DOM(context.html)

    identifiers = ["firstp", "ap", "sndp", "en", "sap", "first"]
    paragraphs1 = dom.find("div p")
    paragraphs2 = dom.find("body p")

    assert that(dom).is_a(DOM)

    assert paragraphs1.length is 6
    assert that(paragraphs1).in_each("attribute['id']").matches(identifiers)

    assert paragraphs2.length is 6
    assert that(paragraphs2).in_each("attribute['id']").matches(identifiers)
開發者ID:eroh92,項目名稱:dominic,代碼行數:17,代碼來源:test_selectors.py

示例2: text_return_the_text_within_element

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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!?")
開發者ID:eroh92,項目名稱:dominic,代碼行數:9,代碼來源:test_manipulation.py

示例3: select_by_attribute_id

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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")
開發者ID:eroh92,項目名稱:dominic,代碼行數:9,代碼來源:test_selectors.py

示例4: select_by_id

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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")
開發者ID:eroh92,項目名稱:dominic,代碼行數:9,代碼來源:test_selectors.py

示例5: select_by_attribute_contains_prefix

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
def select_by_attribute_contains_prefix(context):
    "selecting attribute that contains_prefix certain value"
    dom = DOM(context.html)

    elements = dom.find("ul#packages > li[id|=python]")

    assert that(elements).in_each("attribute['id']").matches(
        [
            'python-django',
            'python-sponge',
            'python-lettuce',
        ]
    )

    found = dom.find("ul#packages > li[id|=java]")
    assert not found
開發者ID:gabrielfalcao,項目名稱:dominic,代碼行數:18,代碼來源:test_selectors.py

示例6: error_tolerance_for_non_well_formed_html

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
def error_tolerance_for_non_well_formed_html(context):
    "DOM(html) ignores a non-well-formed HTML"
    parsed = DOM(context.html)
    assert that(parsed).is_a(DOM)

    head = parsed.find("head title").first()
    assert that(head.text()).equals(u"Gabriel Falcão's page")

    a, div, p = parsed.find("body *")

    assert that(a.text()).equals("My Profile")
    assert that(a.attr("href")).equals("http://github.com/gabrielfalcao")

    assert that(div.text()).looks_like("")
    assert that(div.attr("id")).equals("test")

    assert that(p.text()).equals("Paragraph")
開發者ID:gabrielfalcao,項目名稱:dominic,代碼行數:19,代碼來源:test_manipulation.py

示例7: attr_retrieves_each_attribute_by_name

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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')
開發者ID:gabrielfalcao,項目名稱:dominic,代碼行數:10,代碼來源:test_manipulation.py

示例8: select_by_class_with_many_classes

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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')
開發者ID:eroh92,項目名稱:dominic,代碼行數:10,代碼來源:test_selectors.py

示例9: select_paragraphs

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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
開發者ID:eroh92,項目名稱:dominic,代碼行數:10,代碼來源:test_attributes.py

示例10: select_paragraphs

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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)
開發者ID:eroh92,項目名稱:dominic,代碼行數:11,代碼來源:test_selectors.py

示例11: select_by_child

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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'])
開發者ID:eroh92,項目名稱:dominic,代碼行數:11,代碼來源:test_selectors.py

示例12: html_return_the_html_string

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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>'
    )
開發者ID:eroh92,項目名稱:dominic,代碼行數:11,代碼來源:test_manipulation.py

示例13: select_by_class

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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;")
開發者ID:eroh92,項目名稱:dominic,代碼行數:11,代碼來源:test_selectors.py

示例14: select_by_child_complex

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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'])
開發者ID:eroh92,項目名稱:dominic,代碼行數:11,代碼來源:test_selectors.py

示例15: select_by_attribute_ends_with_with_quotes

# 需要導入模塊: from dominic import DOM [as 別名]
# 或者: from dominic.DOM import find [as 別名]
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',
        ]
    )
開發者ID:gabrielfalcao,項目名稱:dominic,代碼行數:12,代碼來源:test_selectors.py


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