Exemplo n.º 1
0
 def _build_selector(cls, tree, selector_type):
     if selector_type == 'xpath':
         return XpathSelector(tree)
     elif selector_type == 'json':
         return JsonSelector(tree)
     else:
         raise GrabMisuseError('Unknown selector type: %s' % selector_type)
Exemplo n.º 2
0
 def test_select_node(self):
     self.assertEquals({
         'name': 'Mars',
         'cities': [],
         'population': 0
     },
                       JsonSelector(self.tree).select('$[1]')[0].node.value)
Exemplo n.º 3
0
 def test_attr_list(self):
     root = JsonSelector(self.tree)
     self.assertRaises(
         NotImplementedError,
         lambda: root.select('$..population').attr_list('bar'))
Exemplo n.º 4
0
 def test_html(self):
     root = JsonSelector(self.tree)
     self.assertRaises(NotImplementedError,
                       lambda: root.select('$..population')[0].html())
Exemplo n.º 5
0
 def test_text_list(self):
     root = JsonSelector(self.tree)
     self.assertEquals(['7000000000', '0'],
                       root.select('$..population').text_list())
Exemplo n.º 6
0
 def test_select_select(self):
     root = JsonSelector(self.tree)
     self.assertEquals('Mars', root.select('$[1]').select('name').text())
Exemplo n.º 7
0
 def test_population(self):
     self.assertEquals(
         7000000000,
         JsonSelector(self.tree).select('$..population').number())
Exemplo n.º 8
0
 def test_text(self):
     self.assertEquals('Mars',
                       JsonSelector(self.tree).select('$[1].name').text())
Exemplo n.º 9
0
 def test_html(self):
     sel = JsonSelector(self.tree)
     self.assertRaises(NotImplementedError, sel.html)
Exemplo n.º 10
0
 def test_it_works(self):
     sel = JsonSelector(self.tree)
Exemplo n.º 11
0
 def test_attr_list(self):
     root = JsonSelector(self.tree)
     self.assertRaises(NotImplementedError,
         lambda: root.select('$..population').attr_list('bar'))
Exemplo n.º 12
0
 def test_html(self):
     root = JsonSelector(self.tree)
     self.assertRaises(NotImplementedError,
         lambda: root.select('$..population')[0].html())
Exemplo n.º 13
0
 def test_text_list(self):
     root = JsonSelector(self.tree)
     self.assertEquals(['7000000000', '0'],
                       root.select('$..population').text_list())
Exemplo n.º 14
0
 def test_select_select(self):
     root = JsonSelector(self.tree)
     self.assertEquals('Mars', root.select('$[1]').select('name').text())