• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python dsl.descendant函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中xpath.dsl.descendant函数的典型用法代码示例。如果您正苦于以下问题:Python descendant函数的具体用法?Python descendant怎么用?Python descendant使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了descendant函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: link

def link(locator):
    """
    Returns an :class:`Expression` for finding links matching the given locator.

    The query defines a link as an ``a`` element with an ``href`` attribute and will match links
    that meet at least one of the following criteria:
    * the element ``id`` exactly matches the locator
    * the element ``title`` matches the locator
    * the element text matches the locator
    * the ``alt`` of a nested ``img`` element matches the locator

    Args:
        locator (str): A string that identifies the desired links.

    Returns:
        Expression: An :class:`Expression` object matching the desired links.
    """

    expr = x.descendant("a")[x.attr("href")][
        x.attr("id").equals(locator) |
        x.attr("title").is_(locator) |
        x.string.n.is_(locator) |
        x.descendant("img")[x.attr("alt").is_(locator)]]

    return expr
开发者ID:elliterate,项目名称:xpath.py,代码行数:25,代码来源:html.py


示例2: test_selects_a_nodes_text

    def test_selects_a_nodes_text(self):
        xpath = to_xpath(x.descendant("p")[x.text == "Bax"])
        results = self.find_all(xpath)
        self.assertEqual(results[0].text, "Bax")
        self.assertEqual(results[1].get("title"), "monkey")

        xpath = to_xpath(x.descendant("div")[x.descendant("p").text == "Bax"])
        results = self.find_all(xpath)
        self.assertEqual(results[0].get("title"), "fooDiv")
开发者ID:elliterate,项目名称:xpath.py,代码行数:9,代码来源:test_text.py


示例3: test_matches_encoded_unicode_characters

    def test_matches_encoded_unicode_characters(self):
        locator = "이름".encode("UTF-8") if sys.version_info >= (3, 0) else "이름"

        xpath = to_xpath(x.descendant("div")[x.string.n.is_(locator)])
        results = self.find_all(xpath)
        self.assertEqual(results[0].get("id"), "unicode")

        xpath = to_xpath(x.descendant("div")[x.attr("title") == locator])
        results = self.find_all(xpath)
        self.assertEqual(results[0].get("id"), "unicode")
开发者ID:elliterate,项目名称:xpath.py,代码行数:10,代码来源:test_string_literal.py


示例4: test_matches_quotes

    def test_matches_quotes(self):
        locator = "Who's quotes? \"Their\" quotes."

        xpath = to_xpath(x.descendant("div")[x.string.n.is_(locator)])
        results = self.find_all(xpath)
        self.assertEqual(results[0].get("id"), "quotes")

        xpath = to_xpath(x.descendant("div")[x.attr("title") == locator])
        results = self.find_all(xpath)
        self.assertEqual(results[0].get("id"), "quotes")
开发者ID:elliterate,项目名称:xpath.py,代码行数:10,代码来源:test_string_literal.py


示例5: test_second_order_union_aliased_as_plus_sign

    def test_second_order_union_aliased_as_plus_sign(self):
        expr1 = x.descendant("p")
        expr2 = x.descendant("div")
        expr3 = x.descendant("span")

        collection1 = (expr1 + expr2)[x.attr("id") == "union-item-5"]
        collection2 = collection1 + expr3[x.attr("id") == "union-item-6"]

        xpath = to_xpath(collection2)

        results = self.find_all(xpath)
        self.assertEqual(results[0].text, "Fig")
开发者ID:elliterate,项目名称:xpath.py,代码行数:12,代码来源:test_union.py


示例6: test_creates_a_second_order_union

    def test_creates_a_second_order_union(self):
        expr1 = x.descendant("p")
        expr2 = x.descendant("div")
        expr3 = x.descendant("span")

        collection1 = expr1.union(expr2)[x.attr("id") == "union-item-5"]
        collection2 = collection1.union(expr3[x.attr("id") == "union-item-6"])

        xpath = to_xpath(collection2)

        results = self.find_all(xpath)
        self.assertEqual(results[0].text, "Fig")
开发者ID:elliterate,项目名称:xpath.py,代码行数:12,代码来源:test_union.py


示例7: test_where_aliased_as_square_brackets

    def test_where_aliased_as_square_brackets(self):
        expr1 = x.descendant("p")
        expr2 = x.descendant("div")

        collection = expr1.union(expr2)

        xpath1 = to_xpath(collection[x.attr("id").equals("union-item-3")])
        xpath2 = to_xpath(collection[x.attr("id").equals("union-item-4")])

        results = self.find_all(xpath1)
        self.assertEqual(results[0].text, "Cherry")

        results = self.find_all(xpath2)
        self.assertEqual(results[0].text, "Date")
开发者ID:elliterate,项目名称:xpath.py,代码行数:14,代码来源:test_union.py


示例8: test_aliased_as_plus_sign

    def test_aliased_as_plus_sign(self):
        expr1 = x.descendant("p")
        expr2 = x.descendant("div")

        collection = expr1 + expr2

        xpath1 = to_xpath(collection.where(x.attr("id").equals("union-item-3")))
        xpath2 = to_xpath(collection.where(x.attr("id").equals("union-item-4")))

        results = self.find_all(xpath1)
        self.assertEqual(results[0].text, "Cherry")

        results = self.find_all(xpath2)
        self.assertEqual(results[0].text, "Date")
开发者ID:elliterate,项目名称:xpath.py,代码行数:14,代码来源:test_union.py


示例9: test_creates_a_union_expression

    def test_creates_a_union_expression(self):
        expr1 = x.descendant("p")
        expr2 = x.descendant("div")

        collection = expr1.union(expr2)

        xpath1 = to_xpath(collection.where(x.attr("id").equals("union-item-3")))
        xpath2 = to_xpath(collection.where(x.attr("id").equals("union-item-4")))

        results = self.find_all(xpath1)
        self.assertEqual(results[0].text, "Cherry")

        results = self.find_all(xpath2)
        self.assertEqual(results[0].text, "Date")
开发者ID:elliterate,项目名称:xpath.py,代码行数:14,代码来源:test_union.py


示例10: test_aliased_as_right_angle_bracket_equals

 def test_aliased_as_right_angle_bracket_equals(self):
     xpath = to_xpath(x.descendant("p")[x.position() >= 2])
     results = self.find_all(xpath)
     self.assertEqual(results[0].text, "Bax")
     self.assertEqual(results[1].get("title"), "monkey")
     self.assertEqual(results[2].text, "Bax")
     self.assertEqual(results[3].text, "Blah")
开发者ID:elliterate,项目名称:xpath.py,代码行数:7,代码来源:test_gte.py


示例11: test_finds_multiple_kinds_of_nodes_regardless_of_the_context

 def test_finds_multiple_kinds_of_nodes_regardless_of_the_context(self):
     xpath = to_xpath(x.descendant("div")[x.attr("id") == "woo"].anywhere("p", "ul"))
     results = self.find_all(xpath)
     self.assertEqual(inner_text(results[0]), "Blah")
     self.assertEqual(inner_text(results[3]), "A list")
     self.assertEqual(inner_text(results[4]), "A list")
     self.assertEqual(inner_text(results[6]), "Bax")
开发者ID:elliterate,项目名称:xpath.py,代码行数:7,代码来源:test_anywhere.py


示例12: test_used_as_an_expression

    def test_used_as_an_expression(self):
        parent = x.descendant("div")[x.attr("id").equals("union")]

        expr1 = x.descendant("p")
        expr2 = x.descendant("div")

        collection = expr1.union(expr2)

        xpath1 = to_xpath(parent.descendant(collection[x.attr("id").equals("union-item-3")]))
        xpath2 = to_xpath(parent.descendant(collection[x.attr("id").equals("union-item-4")]))

        results = self.find_all(xpath1)
        self.assertEqual(results[0].text, "Cherry")

        results = self.find_all(xpath2)
        self.assertEqual(results[0].text, "Date")
开发者ID:elliterate,项目名称:xpath.py,代码行数:16,代码来源:test_union.py


示例13: test_checks_greater_than_or_equal

 def test_checks_greater_than_or_equal(self):
     xpath = to_xpath(x.descendant("p")[x.position().gte(2)])
     results = self.find_all(xpath)
     self.assertEqual(results[0].text, "Bax")
     self.assertEqual(results[1].get("title"), "monkey")
     self.assertEqual(results[2].text, "Bax")
     self.assertEqual(results[3].text, "Blah")
开发者ID:elliterate,项目名称:xpath.py,代码行数:7,代码来源:test_gte.py


示例14: field

def field(locator):
    """
    Returns an :class:`Expression` for finding form fields matching the given locator.

    The query defines a form field as one of the following:
    * an ``input`` element whose ``type`` is neither "hidden", "image", nor "submit"
    * a ``select`` element
    * a ``textarea`` element

    The query will match form fields that meet at least one of the following criteria:
    * the element ``id`` exactly matches the locator
    * the element ``name`` exactly matches the locator
    * the element ``placeholder`` exactly matches the locator
    * the element ``id`` exactly matches the ``for`` attribute of a corresponding ``label`` element
      whose text matches the locator
    * the element is nested within a ``label`` element whose text matches the locator

    Args:
        locator (str): A string that identifies the desired form fields.
    Return:
        Expression: An :class:`Expression` object matching the desired form fields.
    """

    field_expr = x.descendant("input", "select", "textarea")[
        ~x.attr("type").one_of("hidden", "image", "submit")]
    return _locate_field(field_expr, locator)
开发者ID:elliterate,项目名称:xpath.py,代码行数:26,代码来源:html.py


示例15: _locate_field

def _locate_field(field_expr, locator):
    expr = field_expr[
        x.attr("id").equals(locator) |
        x.attr("name").equals(locator) |
        x.attr("placeholder").equals(locator) |
        x.attr("id").equals(x.anywhere("label")[x.string.n.is_(locator)].attr("for"))]
    expr += x.descendant("label")[x.string.n.is_(locator)].descendant(field_expr)

    return expr
开发者ID:elliterate,项目名称:xpath.py,代码行数:9,代码来源:html.py


示例16: test_finds_all_nodes_when_no_arguments_given_regardless_of_the_context

 def test_finds_all_nodes_when_no_arguments_given_regardless_of_the_context(self):
     xpath = to_xpath(x.descendant("div")[x.attr("id") == "woo"].anywhere())
     results = self.find_all(xpath)
     self.assertEqual(results[0].tag, "html")
     self.assertEqual(results[1].tag, "head")
     self.assertEqual(results[3].tag, "body")
     self.assertEqual(inner_text(results[5]), "Blah")
     self.assertEqual(inner_text(results[9]), "A list")
     self.assertEqual(inner_text(results[12]), "A list")
     self.assertEqual(inner_text(results[14]), "Bax")
开发者ID:elliterate,项目名称:xpath.py,代码行数:10,代码来源:test_anywhere.py


示例17: table

def table(locator):
    """
    Returns an :class:`Expression` for finding tables matching the given locator.

    The query will match tables that meet at least one of the following criteria:
    * the element ``id`` exactly matches the locator
    * the element has a descendant ``caption`` element whose text matches the locator

    Args:
        locator (str): A string that identifies the desired tables.

    Returns:
        Expression: An :class:`Expression` object matching the desired tables.
    """

    expr = x.descendant("table")[
        x.attr("id").equals(locator) |
        x.descendant("caption").is_(locator)]

    return expr
开发者ID:elliterate,项目名称:xpath.py,代码行数:20,代码来源:html.py


示例18: frame

def frame(locator):
    """
    Returns an :class:`Expression` for finding frames matching the given locator.

    The query defines a frame as one of the following:
    * a ``frame`` element
    * an ``iframe`` element

    The query will match frames that meet one of the following criteria:
    * the element ``id`` exactly matches the locator
    * the element ``name`` exactly matches the locator

    Args:
        locator (str): A string that identifies the desired frames.

    Returns:
        Expression: An :class:`Expression` object matching the desired frames.
    """

    frames = x.descendant("frame") + x.descendant("iframe")
    return frames[x.attr("id").equals(locator) | x.attr("name").equals(locator)]
开发者ID:elliterate,项目名称:xpath.py,代码行数:21,代码来源:html.py


示例19: button

def button(locator):
    """
    Returns an :class:`Expression` for finding buttons matching the given locator.

    The query defines a button as one of the following:
    * a ``button`` element
    * an ``input`` element with a ``type`` of "button"
    * an ``input`` element with a ``type`` of "image"
    * an ``input`` element with a ``type`` of "reset"
    * an ``input`` element with a ``type`` of "submit"

    The query will match buttons that meet at least one of the following criteria:
    * the element ``id`` exactly matches the locator
    * the element ``value`` matches the locator
    * the element ``title`` matches the locator
    * the element text matches the locator
    * the element ``alt`` of an "image" ``input`` element matches the locator

    Args:
        locator (str): A string that identifies the desired buttons.

    Returns:
        Expression: An :class:`Expression` object matching the desired buttons.
    """

    expr = x.descendant("button")[
        x.attr("id").equals(locator) |
        x.attr("value").is_(locator) |
        x.attr("title").is_(locator) |
        x.string.n.is_(locator)]
    expr += x.descendant("input")[x.attr("type").one_of("submit", "reset", "image", "button")][
        x.attr("id").equals(locator) |
        x.attr("value").is_(locator) |
        x.attr("title").is_(locator) |
        x.string.n.is_(locator)]
    expr += x.descendant("input")[x.attr("type").equals("image")][x.attr("alt").is_(locator)]

    return expr
开发者ID:elliterate,项目名称:xpath.py,代码行数:38,代码来源:html.py


示例20: test_finds_nodes_which_are_exactly_preceding_the_current_node

    def test_finds_nodes_which_are_exactly_preceding_the_current_node(self):
        woo_div = x.descendant("p")[x.attr("id").equals("wooDiv")]
        gorilla = x.descendant("p")[x.attr("title").equals("gorilla")]

        xpath = to_xpath(woo_div.previous_sibling("p"))
        results = self.find_all(xpath)
        self.assertEqual(inner_text(results[0]), "Bax")

        xpath = to_xpath(woo_div.previous_sibling("ul", "p"))
        results = self.find_all(xpath)
        self.assertEqual(inner_text(results[0]), "Bax")

        xpath = to_xpath(gorilla.previous_sibling("ul", "p"))
        results = self.find_all(xpath)
        self.assertEqual(inner_text(results[0]), "A list")

        xpath = to_xpath(woo_div.previous_sibling("ul", "li"))
        results = self.find_all(xpath)
        self.assertSequenceEqual(results, [])

        xpath = to_xpath(woo_div.previous_sibling())
        results = self.find_all(xpath)
        self.assertEqual(inner_text(results[0]), "Bax")
开发者ID:elliterate,项目名称:xpath.py,代码行数:23,代码来源:test_previous_sibling.py



注:本文中的xpath.dsl.descendant函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python server.UnwrapObject类代码示例发布时间:2022-05-26
下一篇:
Python xpath.find函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap