python - lxml modify tags prevent -


how prevent lxml modify tags

from lxml import etree lxml.html.soupparser import fromstring  html = '<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>' root = fromstring(html) print etree.tostring(root,encoding='utf-8') 

it prints short version of tag

'<iframe width="560" height="315" src="" frameborder="0" allowfullscreen/>' 

how prevent this? needed output

'<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>' 

?

use tostring() method="html":

print etree.tostring(root.find('iframe'), encoding='utf-8', method="html") 

demo:

>>> lxml import etree >>> lxml.html.soupparser import fromstring >>> >>> html = '<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>' >>> root = fromstring(html) >>> print etree.tostring(root.find('iframe'), encoding='utf-8', method="html") <iframe allowfullscreen="allowfullscreen" frameborder="0" height="315" src="" width="560"></iframe> 

Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -