如何使python中的2个表彼此相邻(xpath,lxml,htmlbuilder)

时间:2018-01-24 12:15:35

标签: html css

Hey Guys我想解析2 xmls,我想创建一个HTML,在那里我可以看到xmls的信息。我的代码非常好,但不幸的是它创建了另一列下的一列。但我希望column1在column1的一侧。那是我的代码。它做我想要的,但我希望两个表彼此相邻。

import time
import lxml.html.builder as html
from lxml import etree

xmlData=etree.parse("http://17.19.8.39:8095/this/ressources/p1")
nodeTable=html.BODY(html.TABLE)

nodeData=xmlData.getroot()

xmlData=etree.parse("http://17.19.8.39:8095/this/ressources/p1")
nodeTable3=html.BODY(html.TABLE)


nodeRow5 = html.TH("P1-PreLive")
nodeTable3.append(nodeRow5)

nodeRow2 = html.TH("User-Id")
nodeTable.append(nodeRow2)
nodeRow3 = html.TH("conditions")
nodeTable.append(nodeRow3)
nodeRow4 = html.TH("name")
nodeTable.append(nodeRow4)
for nodeVin in nodeData.xpath("./user[@condition = 'fresh']|./user[@ condition = 'dirty']"):  

    nodeRow = html.TR(html.TD(nodeVin.attrib['id'],style="background-color:##FF0000" ), html.TD(nodeVin.attrib['condition'], style = "background-color:##FF0000"), html.TD(nodeVin.attrib['name'], style = "background-color:##FF0000"))

    nodeTable.append(nodeRow)





xmlData=etree.parse("http://17.19.8.39:8095/this/ressources/p3")
nodeTable4=html.BODY(html.TABLE)


nodeRow5 = html.TH("P3-TuI")
nodeTable4.append(nodeRow5)

nodeTable2  = html.BODY(html.TABLE)
nodeData=xmlData.getroot()

nodeRow2 = html.TH("User-Id")
nodeTable2.append(nodeRow2)
nodeRow3 = html.TH("conditions")
nodeTable2.append(nodeRow3)
nodeRow4 = html.TH("name")
nodeTable2.append(nodeRow4)
for nodeVin in nodeData.xpath("./user[@condition = 'fresh']|./user[@ condition = 'dirty']"):  

    nodeRow = html.TR(html.TD(nodeVin.attrib['id'], style="background-color:#e5e5e5" ), html.TD(nodeVin.attrib['condition'], style = "background-color:##e5e5e5"), html.TD(nodeVin.attrib['name'], style = "background-color:##e5e5e5"))

    nodeTable2.append(nodeRow)

print etree.tostring(nodeTable)
with open("out5.html", "wb") as f:
    f.write(etree.tostring(nodeTable2))
    f.write(etree.tostring(nodeTable))

所以请heeeeelp。实际上它看起来像是:https://www.google.de/search?q=html+tabellen+untereinander&source=lnms&tbm=isch&sa=X&ved=0ahUKEwj7waSLy_DYAhVEKVAKHVvWCdMQ_AUICigB&biw=1696&bih=808#imgrc=_XLuPvtPxS0sLM

0 个答案:

没有答案