Python笔记:在 jupyter notebook中渲染网页

我的未来我决定 提交于 2020-08-10 03:56:59

        渲染有三种方式:分别是 渲染文本、渲染变量、代理页面。

一、渲染文本

将htm网页内容到%%html后面,示例如下:

%%html

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf-8"> 
    <title>chenqionghe</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="page-header">
    <h1>chenqionghe
        <small>yeah buddy! light weight bay!</small>
    </h1>
</div>
<p>geting muscle is not easy</p>

</body>
</html>

渲染效果:

 

二、渲染变量

例如我们经常通过requests抓取网页,可以直接渲染出抓取到的内容,例如通过request抓取网页,直接渲染res.text,代码如下:

import requests
from IPython.display import HTML

res=requests.get("https://www.jd.com/")
HTML(res.text)

渲染效果:

 

三、代理页面

已有页面想通过jupyter显示出来,可以通过IFrame方法渲染,src可以是本地的html,也可以是一个网页地址。

from IPython.display import IFrame
IFrame(src = "https://www.qq.com/", width=1000, height=600)

 

参考: 来源:https://www.cnblogs.com/chenqionghe/

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!