本文整理汇总了Python中selection.backend.XpathSelector类的典型用法代码示例。如果您正苦于以下问题:Python XpathSelector类的具体用法?Python XpathSelector怎么用?Python XpathSelector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XpathSelector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_regexp
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,代码行数:7,代码来源:selector.py
示例2: test_incorrect_xpath
def test_incorrect_xpath(self):
# The lxml xpath function return boolean for following xpath
# This breaks selector internal logic that assumes that only
# list could be returnsed
# So it was fixed and this test was crated
sel = XpathSelector(self.tree).select('//ul/li/text()="oops"')
self.assertEquals(False, sel.exists())
# Selector list is always empty in this special case
# Even if the xpath return True on lxml level
self.assertEquals(True, self.tree.xpath('//ul[1]/li[1]/text()="one"'))
sel = XpathSelector(self.tree).select('//ul[1]/li[1]/text()="one"')
self.assertEquals(False, sel.exists())
开发者ID:pombredanne,项目名称:selection,代码行数:13,代码来源:selector.py
示例3: test_rex
def test_rex(self):
sel = XpathSelector(self.tree).select("//ul/li")
self.assertTrue(isinstance(sel.rex("(\w+)"), RexResultList))
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例4: test_attr_list
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,代码行数:3,代码来源:selector.py
示例5: test_attr_default
def test_attr_default(self):
sel = XpathSelector(self.tree).select("//ul[2]/li[10]")
self.assertRaises(DataNotFound, lambda: sel.attr("class"))
self.assertEquals("DEFAULT", sel.attr("class", default="DEFAULT"))
开发者ID:pombredanne,项目名称:selection,代码行数:4,代码来源:selector.py
示例6: test_number
def test_number(self):
sel = XpathSelector(self.tree).select("//ul/li[4]/text()")
self.assertEquals(4, sel.rex("(\d+)").number())
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例7: test_html
def test_html(self):
sel = XpathSelector(self.tree.xpath("//h1")[0])
self.assertEquals("<h1>test</h1>", sel.html().strip())
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例8: test_one
def test_one(self):
sel = XpathSelector(self.tree).select("//ul/li")
self.assertEquals("SRE_Match", sel.rex("one").one().__class__.__name__)
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例9: test_text_no_default
def test_text_no_default(self):
sel = XpathSelector(self.tree).select("//ul/li/text()")
self.assertRaises(DataNotFound, lambda: sel.rex("(zz)").text())
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例10: test_node_default
def test_node_default(self):
sel = XpathSelector(self.tree).select("//ul/li[10]")
self.assertRaises(DataNotFound, lambda: sel.node())
self.assertEqual("DEFAULT", sel.node(default="DEFAULT"))
开发者ID:pombredanne,项目名称:selection,代码行数:4,代码来源:selector.py
示例11: test_text
def test_text(self):
sel = XpathSelector(self.tree).select("//ul/li")
self.assertEquals("one", sel.text())
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例12: test_text_selector_html
def test_text_selector_html(self):
sel = XpathSelector(self.tree).select("//li/text()").one()
self.assertEquals(u"one", sel.html())
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例13: test_text_selector_select
def test_text_selector_select(self):
sel = XpathSelector(self.tree).select("//li/text()").one()
self.assertRaises(SelectionRuntimeError, lambda: sel.select("foo"))
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例14: test_rex_method
def test_rex_method(self):
sel = XpathSelector(self.tree)
self.assertTrue(isinstance(sel.select("//li").rex("\w*"), RexResultList))
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例15: test_rex_default
def test_rex_default(self):
sel = XpathSelector(self.tree).select("//ul/li[10]")
self.assertRaises(DataNotFound, lambda: sel.rex("zz"))
self.assertEquals("DEFAULT", sel.rex("zz", default="DEFAULT"))
开发者ID:pombredanne,项目名称:selection,代码行数:4,代码来源:selector.py
示例16: test_number_default
def test_number_default(self):
sel = XpathSelector(self.tree).select("//ul/li[10]")
self.assertRaises(DataNotFound, sel.number)
self.assertEquals("DEFAULT", sel.number(default="DEFAULT"))
开发者ID:pombredanne,项目名称:selection,代码行数:4,代码来源:selector.py
示例17: test_node_list
def test_node_list(self):
sel = XpathSelector(self.tree).select("//ul/li")
self.assertEquals(self.tree.xpath("//ul/li"), sel.node_list())
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
示例18: test_assert_exists
def test_assert_exists(self):
sel = XpathSelector(self.tree).select("//ul/li")
sel.assert_exists()
sel = XpathSelector(self.tree).select("//ul/li[10]")
self.assertRaises(DataNotFound, sel.assert_exists)
开发者ID:pombredanne,项目名称:selection,代码行数:6,代码来源:selector.py
示例19: test_exists
def test_exists(self):
sel = XpathSelector(self.tree).select("//ul/li[4]")
self.assertEquals(True, sel.exists())
sel = XpathSelector(self.tree).select("//ul/li[5]")
self.assertEquals(False, sel.exists())
开发者ID:pombredanne,项目名称:selection,代码行数:6,代码来源:selector.py
示例20: test_text_default_value
def test_text_default_value(self):
sel = XpathSelector(self.tree).select("//ul/li/text()")
self.assertEquals("DEFAULT", sel.rex("(zz)").text(default="DEFAULT"))
开发者ID:pombredanne,项目名称:selection,代码行数:3,代码来源:selector.py
注:本文中的selection.backend.XpathSelector类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论