如何在PYHTML库中渲染RAW HTML 我无法将PANDAS .TOHTML()函数生成的表渲染到我的PYHTML生成的代码中。 s = h.html( H.head( h.title(“学生数据”) ...

问题描述 投票:0回答:1

<table border="1" class="dataframe"> <thead> <tr style="text-align: right;"> <th>Student id</th> <th>Course id</th> <th>Marks</th> </tr> </thead> <tbody> <tr> <td>1002</td> <td>2001</td> <td>67</td> </tr> </tbody> </table>
这是我的HTML表的近似结构)

您可以将输出从
sdf.to_html()
tag和通过

div

中包含
python html
1个回答
0
投票
,例如,例如

import pyhtml as h my_table = """ <table border="1" class="dataframe"> <thead> <tr style="text-align: right;"> <th>Student id</th> <th>Course id</th> <th>Marks</th> </tr> </thead> <tbody> <tr> <td>1002</td> <td>2001</td> <td>67</td> </tr> </tbody> </table>""" s = h.html( h.head( h.title("Student Data") ), h.body( h.h1( "Student Details" ), (h.div(my_table, _safe=True)) ) ) print(s.render())

输出:
<!DOCTYPE html>
<html>
  <head>
    <title>
      Student Data
    </title>
  </head>
  <body>
    <h1>
      Student Details
    </h1>
    <div>
      <table border="1" class="dataframe">
       <thead> <tr style="text-align: right;"> 
      <th>Student id</th> <th>Course id</th> <th>Marks</th> </tr> 
      </thead> 
      <tbody> 
      <tr> <td>1002</td> <td>2001</td> <td>67</td> </tr> 
      </tbody> 
      </table> 
                       
    </div>
  </body>
</html>
    

© www.soinside.com 2019 - 2025. All rights reserved.