本文整理汇总了Python中selection.backend.XpathSelector.rex方法的典型用法代码示例。如果您正苦于以下问题:Python XpathSelector.rex方法的具体用法?Python XpathSelector.rex怎么用?Python XpathSelector.rex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selection.backend.XpathSelector
的用法示例。
在下文中一共展示了XpathSelector.rex方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_number
# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import rex [as 别名]
def test_number(self):
sel = XpathSelector(self.tree).select("//ul/li[4]/text()")
self.assertEquals(4, sel.rex("(\d+)").number())
示例2: test_text_no_default
# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import rex [as 别名]
def test_text_no_default(self):
sel = XpathSelector(self.tree).select("//ul/li/text()")
self.assertRaises(DataNotFound, lambda: sel.rex("(zz)").text())
示例3: test_text_default_value
# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import rex [as 别名]
def test_text_default_value(self):
sel = XpathSelector(self.tree).select("//ul/li/text()")
self.assertEquals("DEFAULT", sel.rex("(zz)").text(default="DEFAULT"))
示例4: test_one
# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import rex [as 别名]
def test_one(self):
sel = XpathSelector(self.tree).select("//ul/li")
self.assertEquals("SRE_Match", sel.rex("one").one().__class__.__name__)
示例5: test_text
# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import rex [as 别名]
def test_text(self):
sel = XpathSelector(self.tree).select("//ul/li/text()")
self.assertEquals("one", sel.rex("(\w+)").text())
示例6: test_rex
# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import rex [as 别名]
def test_rex(self):
sel = XpathSelector(self.tree).select("//ul/li")
self.assertTrue(isinstance(sel.rex("(\w+)"), RexResultList))
示例7: test_rex_default
# 需要导入模块: from selection.backend import XpathSelector [as 别名]
# 或者: from selection.backend.XpathSelector import rex [as 别名]
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"))