splash

1.      splash简介

Splash是一个JavaScript渲染服务,是一个带有HTTP API的轻量级浏览器,同时它对接了Python中的Twisted和QT库。利用它,我们同样可以实现动态渲染页面的抓取。

利用Splash,我们可以实现如下功能:

异步方式处理多个网页渲染过程;

获取渲染后的页面的源代码或截图;

通过关闭图片渲染或者使用Adblock规则来加快页面渲染速度;

可执行特定的JavaScript脚本;

可通过Lua脚本来控制页面渲染过程;

获取渲染的详细过程并通过HAR(HTTP Archive)格式呈现。

2.      运行及使用

2.1.    运行

启动docker,实验位于windows平台,点击Docker Quickstart Terminal即可。

拉取镜像splash

$ docker pull scrapinghub/splash

启动容器:

$ docker run -p 8050:8050 scrapinghub/splash

表示:Splash现在在端口8050(http)可用。

2.2.    使用

浏览器访问http://192.168.99.100:8050

结果是splash界面。

释义:

左侧为简介,略;

右侧上层为目标网页地址,默认为baidu.com;

右侧下层为当前解析脚本,它使用lua语言。

输入目标网页地址:天眼查

https://www.tianyancha.com/search?key=%E9%98%BF%E9%87%8C%E5%B7%B4%E5%B7%B4

然后render me,结果如下:

输出内容由lua脚本指定。

默认输出三种信息,分别是html,png,har。

实际上是Splash执行了整个网页的渲染过程,包括CSS、JavaScript的加载等过程,呈现的页面和浏览器中得到的结果完全一致,然后返回渲染截图、HAR加载统计数据、网页的源代码。

当然可以定制脚本,但一般不需要写lua脚本,有相关的python包。

3.      lua脚本

默认脚本如下:

function main(splash, args)

assert(splash:go(args.url))

assert(splash:wait(0.5))

return {

html = splash:html(),

png = splash:png(),

har = splash:har(),

}

end

4.      总结

总而言之,splash是一个渲染引擎。

输入url,根据lua脚本返回相应对象。

它能在js执行前执行本地js(用于环境模拟)。

5.      接口

通常使用的是http api,所以,这里提及的都是http接口。

参考文档:https://splash.readthedocs.io/en/stable/api.html#render-html

http接口使用get方法访问即可。

概念:

endpoint:执行主体,决定返回的数据类型。常用的有execute,run,render.html,render.png。

5.1.    返回的数据类型

render.html

Return the HTML of the javascript-rendered page.

示例:curl 'http://localhost:8050/render.html?url=http://domain.com/page-with-javascript.html&timeout=10&wait=0.5'

render.png

Return an image (in PNG format) of the javascript-rendered page.

render.jpeg

Return an image (in JPEG format) of the javascript-rendered page.

示例:

# render with default quality

curl 'http://localhost:8050/render.jpeg?url=http://domain.com/'

# render with low quality

curl 'http://localhost:8050/render.jpeg?url=http://domain.com/&quality=30'

render.har

Return information about Splash interaction with a website in HAR format. It includes information about requests made, responses received, timings, headers, etc.

返回HAR格式数据,包括请示生成,响应,时间线,头部等。

render.json

Return a json-encoded dictionary with information about javascript-rendered webpage. It can include HTML, PNG and other information, based on arguments passed.

Return a json-encoded dictionary with information about javascript-rendered webpage. It can include HTML, PNG and other information, based on arguments passed.

重点:

execute

Execute a custom rendering script and return a result.

run

它与execute相同,但接口形式不同,简单来说,不需要包裹函数体。

This endpoint is the same as execute, but it wraps lua_source in function main(splash, args) ... endautomatically. For example, if you’re sending this script to execute:

在execute中应该这样写:

function main(splash, args)

assert(splash:go(args.url))

assert(splash:wait(1.0))

return splash:html()

end

equivalent script for run endpoint would be

它等效于run

assert(splash:go(args.url))

assert(splash:wait(1.0))

return splash:html()

executer的参数

Arguments:

lua_source : string : required(重点)

Browser automation script. See Splash Scripts Tutorial for more info.

timeout : float : optional

Same as ‘timeout’ argument for render.html.

allowed_domains : string : optional

Same as ‘allowed_domains’ argument for render.html.

proxy : string : optional

Same as ‘proxy’ argument for render.html.

filters : string : optional

Same as ‘filters’ argument for render.html.

save_args : JSON array or a comma-separated string : optional

Same as ‘save_args’ argument for render.html. Note that you can save not only default Splash arguments, but any other parameters as well.

load_args : JSON object or a string : optional

Same as ‘load_args’ argument for render.html. Note that you can load not only default Splash arguments, but any other parameters as well.

转载于:https://www.cnblogs.com/wodeboke-y/p/11400021.html

splash-简介及入门相关推荐

  1. Python之路【第一篇】:Python简介和入门

    Python之路[第一篇]:Python简介和入门 Python简介 Python前世今生 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗 ...

  2. AI之FL:联邦学习(Federated Learning)的简介、入门、应用之详细攻略

    AI之FL:联邦学习(Federated Learning)的简介.入门.应用之详细攻略 导读       2019 年2 月,微众银行 AI 团队自主研发的全球首个工业级联邦学习框架 FATE(Fe ...

  3. DL之CG:Computational Graph计算图的简介、入门、使用之详细攻略

    DL之CG:Computational Graph计算图的简介.入门.使用之详细攻略 目录 计算图的简介 计算图的入门 CG与局部计算 计算图的使用 计算图的简介 计算图Computational G ...

  4. Windows PowerShell:Windows PowerShell的简介、入门、使用方法之详细攻略

    Windows PowerShell:Windows PowerShell的简介.入门.使用方法之详细攻略 目录 Windows PowerShell的简介 PowerShell VS Unix Sh ...

  5. Ubuntu:Ubuntu下安装Anaconda和Tensorflow的简介、入门、安装流程之详细攻略

    Ubuntu:Ubuntu下安装Anaconda和Tensorflow的简介.入门.安装流程之详细攻略 目录 安装流程 1.安装nvidia显卡驱动 2.安装cuda8 3.安装Cudnn 4.Ana ...

  6. Py之GUI之PyQt:PyQt5的简介、入门、安装(QtCreator和QtDesigner)图文教程之详细攻略

    Py之GUI之PyQt:PyQt5的简介.入门.安装(QtCreator和QtDesigner)图文教程之详细攻略 目录 PyQt的简介 1.Qt特点 2.QT中QT Widgets Applicat ...

  7. TF学习——TF之Tensorboard:Tensorflow之Tensorboard可视化简介、入门、使用方法之详细攻略

    TF学习--TF之Tensorboard:Tensorflow之Tensorboard可视化简介.入门.使用方法之详细攻略 目录 Tensorboard简介 Tensorboard各个板块入门 Ten ...

  8. OpenCV-Python实战(18)——深度学习简介与入门示例

    OpenCV-Python实战(18)--深度学习简介与入门示例 0. 前言 1. 计算机视觉中的深度学习简介 1.1 深度学习的特点 1.2 深度学习大爆发 2. 用于图像分类的深度学习简介 3. ...

  9. Python自动化开发【1】:Python简介和入门

    Python自动化开发之路 [第1篇]:Python简介和入门 编程与编程语言 一 编程与编程语言python是一门编程语言,作为学习python的开始,需要事先搞明白:编程的目的是什么?什么是编程语 ...

  10. 【ENVI入门系列】01.ENVI产品简介与入门

    [ENVI入门系列]01.ENVI产品简介与入门 (2014-09-22 10:18:21) 转载▼ 标签: 杂谈 分类: ENVI 版权声明:本教程涉及到的数据仅供练习使用,禁止用于商业用途. 目录 ...

最新文章

  1. 人类首张脑电波连接全图问世
  2. “记住密码“功能的正确设计
  3. thrift介绍及应用(四)—hadoop的thrift接口
  4. multipartfile 获取音频时长_QQ音乐移动端加入倍速播放,蓄力长音频发展 | 产品观察...
  5. 华硕笔记本的U盘启动
  6. 股票历史数据-股票历史交易数据下载成Excel,股票历史交易数据查询
  7. 杭电2019多校第八场 Acesrc and Good Numbers——思维打表oeis
  8. 使用opencv在视频中插入文字、图片;生成特定文字视频
  9. html两列合并一列,如何将excel中两列数据合并到一列呢
  10. 小白看了也会选:数据分析的常见工具有哪些
  11. 大数据精选面试题160道
  12. echart vue
  13. (九)巴菲特与索罗斯的投资习惯:术业有专攻
  14. css3之BFC、IFC、GFC和FFC
  15. python3通过Beautif和XPath分别爬取“小猪短租-北京”租房信息,并对比时间效率(附源代码)...
  16. java程序中编写sql语句的单引号、双引号问题
  17. PathAFL论文阅读+源码分析
  18. 安装SQL Server以及SSMS
  19. 4个好用的图片去水印工具,图片去水印这样做就对了
  20. python生成随机数组_python3.x 生成3维随机数组实例

热门文章

  1. [NOIP2007 普及组] 守望者的逃离
  2. linux 系统账户 和 普通账户 的区别
  3. 计算机学院新生入学致辞,计算机科学与技术学院召开迎新大会 欢迎14级新生入学...
  4. 【新书上架】 | 《全栈应用开发:精益实践》——历时两年二十万余字
  5. 【2018/10/16测试T3】长者
  6. Python批量下载网易云音乐飙升榜所有音乐文件
  7. .NET线程方法:Thread.Start()与ThreadPool.QueueUserWorkItem()
  8. [面试题]java中final finally finalized 的区别是什么?
  9. ShardingSphere-JDBC5.2整合mybatisPlus入门
  10. 将excel中的多个工作表sheet合成一个工作表