本文整理汇总了Python中lxml.html.builder.DIV.attrib['height']方法的典型用法代码示例。如果您正苦于以下问题:Python DIV.attrib['height']方法的具体用法?Python DIV.attrib['height']怎么用?Python DIV.attrib['height']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lxml.html.builder.DIV
的用法示例。
在下文中一共展示了DIV.attrib['height']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_custom_embed_code
# 需要导入模块: from lxml.html.builder import DIV [as 别名]
# 或者: from lxml.html.builder.DIV import attrib['height'] [as 别名]
def set_custom_embed_code(self, data):
""" Return the code that embed the code. Could be with the
original size or the custom chosen.
"""
if 'embed_html' not in data:
return
tree = etree.HTML(data['embed_html'])
sel = cssselect.CSSSelector('body > *')
el = sel(tree)
# add a div around if there is more than one element into code
if len(el) > 1:
el = DIV(*el)
else:
el = el[0]
# width and height attributes should not be set in a div tag
if el.tag in ['iframe', 'object']:
if data.get('width', None):
el.attrib['width'] = data['width'] and str(data['width']) or el.attrib['width']
if data.get('height', None):
el.attrib['height'] = data['height'] and str(data['height']) or el.attrib['height']
data['embed_html'] = html.tostring(el)