当前位置: 首页>>代码示例>>Python>>正文


Python XpathSelector.select方法代码示例

本文整理汇总了Python中selection.backend.XpathSelector.select方法的典型用法代码示例。如果您正苦于以下问题:Python XpathSelector.select方法的具体用法?Python XpathSelector.select怎么用?Python XpathSelector.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在selection.backend.XpathSelector的用法示例。


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

示例1: test_regexp

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_regexp(self):
     html = '<div><h1 id="h1">foo</h1><h2>bar</h2></div>'
     sel = XpathSelector(fromstring(html))
     self.assertEqual('h2', sel.select('//*[re:test(text(), "b.r")]')\
                               .node().tag)
     self.assertEqual('foo', sel.select('//*[re:test(@id, "^h\d+$")]'
                                        '/text()').text())
开发者ID:danillab,项目名称:selection,代码行数:9,代码来源:selector.py

示例2: test_attr_list

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_attr_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(["li-1", "li-2"]), set(root.select('//ul[@id="second-list"]/li').attr_list("class")))
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py

示例3: test_attr_does_not_exist

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_attr_does_not_exist(self):
     root = XpathSelector(self.tree)
     self.assertRaises(DataNotFound, lambda: root.select("//ul[1]").attr("id-xxx"))
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py

示例4: test_attr_with_default_value

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_attr_with_default_value(self):
     root = XpathSelector(self.tree)
     self.assertEqual("z", root.select("//ul[2]").attr("id-xxx", default="z"))
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py

示例5: test_attr

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_attr(self):
     root = XpathSelector(self.tree)
     self.assertEqual("second-list", root.select("//ul[2]").attr("id"))
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py

示例6: test_text_list

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_text_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(["one", "yet one"]), set(root.select("//ul/li[1]").text_list()))
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py

示例7: test_text_list

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_text_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['one', 'yet one']),
                       set(root.select('//ul/li[1]').text_list()))
开发者ID:danillab,项目名称:selection,代码行数:6,代码来源:selector.py

示例8: test_select_node

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_select_node(self):
     sel = XpathSelector(self.tree)
     self.assertEquals("test", sel.select("//h1")[0]._node.text)
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py

示例9: test_xpath_concat_function

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_xpath_concat_function(self):
     html = '<a href="index.html"></a>'
     sel = XpathSelector(fromstring(html))
     self.assertEqual('/index.html', sel.select('concat("/",//a/@href)')\
                               .text())
开发者ID:danillab,项目名称:selection,代码行数:7,代码来源:selector.py

示例10: test_attr_list

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_attr_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['li-1', 'li-2']),
                       set(root.select('//ul[@id="second-list"]/li')
                               .attr_list('class')))
开发者ID:danillab,项目名称:selection,代码行数:7,代码来源:selector.py

示例11: test_attr_with_default_value

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_attr_with_default_value(self):
     root = XpathSelector(self.tree)
     self.assertEqual('z', root.select('//ul[2]').attr('id-xxx',
                                                       default='z'))
开发者ID:danillab,项目名称:selection,代码行数:6,代码来源:selector.py

示例12: test_rex_method

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_rex_method(self):
     sel = XpathSelector(self.tree)
     self.assertTrue(isinstance(sel.select("//li").rex("\w*"), RexResultList))
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py

示例13: test_sel_list_number

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_sel_list_number(self):
     sel = XpathSelector(self.tree)
     self.assertEquals(4, sel.select('//ul/li[last()]').number())
     self.assertEquals(6, sel.select('//ul/li[last()]/@id').number())
开发者ID:danillab,项目名称:selection,代码行数:6,代码来源:selector.py

示例14: test_text_selector_select

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_text_selector_select(self):
     sel = XpathSelector(self.tree).select("//li/text()").one()
     self.assertRaises(SelectionRuntimeError, lambda: sel.select("foo"))
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py

示例15: test_select_select

# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import select [as 别名]
 def test_select_select(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(["one", "yet one"]), set([x.text() for x in root.select("//ul").select("./li[1]")]))
开发者ID:pombredanne,项目名称:selection,代码行数:5,代码来源:selector.py


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