Hello, I'd like to find and replace an element in an HTML file. I can't figure out why getparent() doesn't work as expected:
============== import lxml.html from lxml.html import builder as E import lxml.etree as et import lxml.etree as et parser = et.HTMLParser(remove_blank_text=True,recover=True) with open("template.tmpl") as tempfile: template_tree = et.parse(tempfile, parser=parser) template_root = template_tree.getroot() #BAD FOO = template_root.find('.//FOO') FOO = template_root.xpath('//FOO') if len(FOO): print("FOO:",FOO) #AttributeError: 'list' object has no attribute 'getparent' parent = FOO.getparent() parent.insert(parent.index(FOO)+1,ET.XML("<bar/>")) #Remove FOO, no longer needed else: print("Not FOO") ============== What am I doing wrong? Thank you. _______________________________________________ lxml - The Python XML Toolkit mailing list -- lxml@python.org To unsubscribe send an email to lxml-le...@python.org https://mail.python.org/mailman3/lists/lxml.python.org/ Member address: arch...@mail-archive.com