예제 #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)
예제 #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'])
예제 #3
0
 def test_phone(self):
     ext = base.Extractor(xpath='//strong/text()', regexp=r'\d+-\d+')
     self.assertEqual(ext.extract(self.html), [['555-1234']])
예제 #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])
예제 #5
0
 def test_address(self):
     ext = base.Extractor(regexp=r'(\d+[^,]+),')
     self.assertEqual(ext.extract(self.html), ['123 Foo Road'])
예제 #6
0
 def test_regexp2(self):
     ext = base.Extractor(regexp=r'(\d+.+\d+)')
     self.assertEqual(ext.extract(self.text), ['3.14'])
예제 #7
0
 def test_regexp1(self):
     ext = base.Extractor(regexp=r'\'(.*)\'')
     self.assertEqual(ext.extract(self.text), ['pi'])
예제 #8
0
 def test_third(self):
     ext = base.Extractor(xpath='//li[contains(@class,"third")]/text()')
     self.assertEqual(ext.extract(self.resp), ['3'])
예제 #9
0
 def test_even(self):
     ext = base.Extractor(xpath='//li[contains(@class,"even")]/text()')
     self.assertEqual(ext.extract(self.resp), ['2'])