示例#1
0
 def test_xpath_attr(self):
     testxml = '''<root>
         <div>
             <p x="a">Foo</p>
         </div>
     </root>'''
     doc = compat_etree_fromstring(testxml)
     self.assertEqual(xpath_attr(doc, 'div/p', 'x'), 'a')
     self.assertEqual(xpath_attr(doc, 'div/bar', 'x'), None)
     self.assertEqual(xpath_attr(doc, 'div/p', 'y'), None)
     self.assertEqual(xpath_attr(doc, 'div/bar', 'x', default='default'),
                      'default')
     self.assertEqual(xpath_attr(doc, 'div/p', 'y', default='default'),
                      'default')
     self.assertRaises(ExtractorError,
                       xpath_attr,
                       doc,
                       'div/bar',
                       'x',
                       fatal=True)
     self.assertRaises(ExtractorError,
                       xpath_attr,
                       doc,
                       'div/p',
                       'y',
                       fatal=True)
示例#2
0
 def test_xpath_attr(self):
     testxml = '''<root>
         <div>
             <p x="a">Foo</p>
         </div>
     </root>'''
     doc = compat_etree_fromstring(testxml)
     self.assertEqual(xpath_attr(doc, 'div/p', 'x'), 'a')
     self.assertEqual(xpath_attr(doc, 'div/bar', 'x'), None)
     self.assertEqual(xpath_attr(doc, 'div/p', 'y'), None)
     self.assertEqual(xpath_attr(doc, 'div/bar', 'x', default='default'), 'default')
     self.assertEqual(xpath_attr(doc, 'div/p', 'y', default='default'), 'default')
     self.assertRaises(ExtractorError, xpath_attr, doc, 'div/bar', 'x', fatal=True)
     self.assertRaises(ExtractorError, xpath_attr, doc, 'div/p', 'y', fatal=True)
示例#3
0
 def test_xpath_attr(self):
     testxml = """<root>
         <div>
             <p x="a">Foo</p>
         </div>
     </root>"""
     doc = compat_etree_fromstring(testxml)
     self.assertEqual(xpath_attr(doc, "div/p", "x"), "a")
     self.assertEqual(xpath_attr(doc, "div/bar", "x"), None)
     self.assertEqual(xpath_attr(doc, "div/p", "y"), None)
     self.assertEqual(xpath_attr(doc, "div/bar", "x", default="default"), "default")
     self.assertEqual(xpath_attr(doc, "div/p", "y", default="default"), "default")
     self.assertRaises(ExtractorError, xpath_attr, doc, "div/bar", "x", fatal=True)
     self.assertRaises(ExtractorError, xpath_attr, doc, "div/p", "y", fatal=True)