Ejemplo n.º 1
0
 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())
Ejemplo n.º 2
0
 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())
Ejemplo n.º 3
0
 def test_select_node(self):
     sel = XpathSelector(self.tree)
     self.assertEquals("test", sel.select("//h1")[0]._node.text)
Ejemplo n.º 4
0
 def test_rex_method(self):
     sel = XpathSelector(self.tree)
     self.assertTrue(isinstance(sel.select("//li").rex("\w*"), RexResultList))
Ejemplo n.º 5
0
 def test_attr_does_not_exist(self):
     root = XpathSelector(self.tree)
     self.assertRaises(DataNotFound, lambda: root.select("//ul[1]").attr("id-xxx"))
Ejemplo n.º 6
0
 def test_attr(self):
     root = XpathSelector(self.tree)
     self.assertEqual("second-list", root.select("//ul[2]").attr("id"))
Ejemplo n.º 7
0
 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]")]))
Ejemplo n.º 8
0
 def test_select_node(self):
     sel = XpathSelector(self.tree)
     self.assertEquals('test', sel.select('//h1')[0]._node.text)
Ejemplo n.º 9
0
 def test_select_node(self):
     sel = XpathSelector(self.tree)
     self.assertEquals('test', sel.select('//h1')[0]._node.text)
Ejemplo n.º 10
0
 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())
Ejemplo n.º 11
0
 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')))
Ejemplo n.º 12
0
 def test_attr_with_default_value(self):
     root = XpathSelector(self.tree)
     self.assertEqual('z', root.select('//ul[2]').attr('id-xxx',
                                                       default='z'))
Ejemplo n.º 13
0
 def test_attr(self):
     root = XpathSelector(self.tree)
     self.assertEqual('second-list', root.select('//ul[2]').attr('id'))
Ejemplo n.º 14
0
 def test_text_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['one', 'yet one']),
                       set(root.select('//ul/li[1]').text_list()))
Ejemplo n.º 15
0
 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())
Ejemplo n.º 16
0
 def test_text_selector_select(self):
     sel = XpathSelector(self.tree).select('//li/text()').one()
     self.assertRaises(SelectionRuntimeError, lambda: sel.select('foo'))
Ejemplo n.º 17
0
 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]')]))
Ejemplo n.º 18
0
 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())
Ejemplo n.º 19
0
 def test_text_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(['one', 'yet one']),
                       set(root.select('//ul/li[1]').text_list()))
Ejemplo n.º 20
0
 def test_selector_number(self):
     sel = XpathSelector(self.tree)
     self.assertEquals(4, sel.select('//ul/li[last()]').one().number())
     self.assertEquals(6, sel.select('//ul/li[last()]/@id').one().number())
Ejemplo n.º 21
0
 def test_attr(self):
     root = XpathSelector(self.tree)
     self.assertEqual('second-list', root.select('//ul[2]').attr('id'))
Ejemplo n.º 22
0
 def test_text_list(self):
     root = XpathSelector(self.tree)
     self.assertEquals(set(["one", "yet one"]), set(root.select("//ul/li[1]").text_list()))
Ejemplo n.º 23
0
 def test_attr_with_default_value(self):
     root = XpathSelector(self.tree)
     self.assertEqual('z',
                      root.select('//ul[2]').attr('id-xxx', default='z'))
Ejemplo n.º 24
0
 def test_attr_with_default_value(self):
     root = XpathSelector(self.tree)
     self.assertEqual("z", root.select("//ul[2]").attr("id-xxx", default="z"))
Ejemplo n.º 25
0
 def test_attr_does_not_exist(self):
     root = XpathSelector(self.tree)
     self.assertRaises(DataNotFound,
                       lambda: root.select('//ul[1]').attr('id-xxx'))
Ejemplo n.º 26
0
 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")))
Ejemplo n.º 27
0
 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')))
Ejemplo n.º 28
0
 def test_text_selector_select(self):
     sel = XpathSelector(self.tree).select("//li/text()").one()
     self.assertRaises(SelectionRuntimeError, lambda: sel.select("foo"))
Ejemplo n.º 29
0
 def test_rex_method(self):
     sel = XpathSelector(self.tree)
     self.assertTrue(
         isinstance(sel.select('//li').rex('\w*'), RexResultList))
Ejemplo n.º 30
0
 def test_selector_number(self):
     sel = XpathSelector(self.tree)
     self.assertEquals(4, sel.select("//ul/li[last()]").one().number())
     self.assertEquals(6, sel.select("//ul/li[last()]/@id").one().number())
Ejemplo n.º 31
0
 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]')]))