Ejemplo n.º 1
0
 def test_all1(self):
     ext = base.Extractor(
         xpath='//p/text()',
         regexp=r'(\d+.+\d+)',
         fn=lambda matches, r, s: math.trunc(float(matches[0][0])))
     self.assertEqual(ext.extract(self.text), 3)
Ejemplo n.º 2
0
 def test_all2(self):
     ext = base.Extractor(xpath='//p[not(child::string)]/text()',
                          regexp=r'(\d+[^.]+).',
                          fn=lambda matches, r, s: matches[0])
     self.assertEqual(ext.extract(self.html),
                      ['123 Foo Road, San Jose, CA'])
Ejemplo n.º 3
0
 def test_phone(self):
     ext = base.Extractor(xpath='//strong/text()', regexp=r'\d+-\d+')
     self.assertEqual(ext.extract(self.html), [['555-1234']])
Ejemplo n.º 4
0
 def test_process(self):
     ext = base.Extractor(
         xpath='//li/text()',
         fn=lambda matches, r, s: [self.map[m] * 3 for m in matches])
     self.assertEqual(ext.extract(self.text), [3, 6, 9])
Ejemplo n.º 5
0
 def test_address(self):
     ext = base.Extractor(regexp=r'(\d+[^,]+),')
     self.assertEqual(ext.extract(self.html), ['123 Foo Road'])
Ejemplo n.º 6
0
 def test_regexp2(self):
     ext = base.Extractor(regexp=r'(\d+.+\d+)')
     self.assertEqual(ext.extract(self.text), ['3.14'])
Ejemplo n.º 7
0
 def test_regexp1(self):
     ext = base.Extractor(regexp=r'\'(.*)\'')
     self.assertEqual(ext.extract(self.text), ['pi'])
Ejemplo n.º 8
0
 def test_third(self):
     ext = base.Extractor(xpath='//li[contains(@class,"third")]/text()')
     self.assertEqual(ext.extract(self.resp), ['3'])
Ejemplo n.º 9
0
 def test_even(self):
     ext = base.Extractor(xpath='//li[contains(@class,"even")]/text()')
     self.assertEqual(ext.extract(self.resp), ['2'])