【发布时间】:2021-03-16 13:50:01
【问题描述】:
我想在python的帮助下以jpg格式保存到由html/css代码生成的输出。在谷歌上搜索时,我发现我们可以使用 IPython.display.HTML 来实现这一点。但是这个库只适用于 Python 2.0,将来会被弃用,所以想用 Python 3.0 + 实现这一点,还需要将输出保存为 html+css 代码生成的 JPG 格式。任何人都可以帮忙,如何实现这一点? 下面是我能够在 python 中呈现 html 输出的代码。
#rendering frontend
from IPython.display import display, Image
IPython.display.HTML(filename='/content/drive/MyDrive/Analysed/Task2/test_page.html')
其中,test_page.html 文件包含简单的 html css 代码。
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
<title>Hello</title>
<style>
.t{width:100px;height:100px;background-color:green;}
.container{width:1000px;height:700px;border:1px solid black;}
</style>
</head>
<body>
<div class="container">
<div class="t">
<p>Hello , How's day ?</p>
</div>
</div>
</body>
</html>
这是我用上面的代码得到的输出,我想保存在 jpg 中 与蟒蛇。 html+css rendered output
【问题讨论】:
-
您能帮我们添加代码吗?
-
是的,我已经添加了代码和输出