当前位置: 首页>>代码示例>>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;未经允许,请勿转载。