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.

splash-简介及入门的更多相关文章

  1. JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式

    相关链接: JS面向对象(1) -- 简介,入门,系统常用类,自定义类,constructor,typeof,instanceof,对象在内存中的表现形式 JS面向对象(2) -- this的使用,对 ...

  2. python3-day1-python简介及入门

    python简介及入门 python简介 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本解释程序,做为 ...

  3. Robot Framework-工具简介及入门使用

    Robot Framework-Mac版本安装 Robot Framework-Windows版本安装 Robot Framework-工具简介及入门使用 Robot Framework-Databa ...

  4. Linux内核学习笔记-1.简介和入门

    原创文章,转载请注明:Linux内核学习笔记-1.简介和入门 By Lucio.Yang 部分内容来自:Linux Kernel Development(Third Edition),Robert L ...

  5. Akka 简介与入门

    Akka 简介与入门 http://www.thinksaas.cn/group/topic/344095/ 参考官网  http://akka.io/ 开源代码  https://github.co ...

  6. 【转】Docker简介与入门

    转自:https://segmentfault.com/a/1190000000448808 Docker是个新生的事物,概念类似虚拟化.网上关于Docker入门的东西已经很多了.不过本文探讨了Doc ...

  7. Quartz入门例子简介 从入门到菜鸟(一)

    转: Quartz入门例子简介 从入门到菜鸟(一) 2016年11月19日 22:58:24 爱种鱼的猫 阅读数:4039   刚接触quartz这个词并不是在学习过程中...而是WOW里面的界面插件 ...

  8. Lombok简介及入门使用 (转载)

    Lombok简介及入门使用 lombok既是一个IDE插件,也是一个项目要依赖的jar包. Intellij idea开发的话需要安装Lombok plugin,同时设置 Setting -> ...

  9. Shiro简介、入门案例、web容器的集成

    目的: shiro简介 Shiro入门案例 Shiro与web容器的集成 shiro简介(中文官网:https://www.w3cschool.cn/shiro/andc1if0.html) 1.什么 ...

  10. Python【第一章】:简介和入门

    ython简介 Python的创始人为Guido van Rossum.1989年圣诞节期间,在阿姆斯特丹,Guido为了打发圣诞节的无趣,决心开发一个新的脚本解释程序,做为ABC 语言的一种继承.之 ...

随机推荐

  1. 1.Java多线程之wait和notify

    1.首先我们来从概念上理解一下这两个方法: (1)obj.wait(),当obj对象调用wait方法时,这个方法会让当前执行了这条语句的线程处于等待状态(或者说阻塞状态),并释放调用wait方法的对象 ...

  2. 故障解决 | win10没声音及找不到Realtek高清音频管理器

    重装 win10 系统后,电脑没声音,更新驱动以及万不得已下载驱动精灵都没有解决. 后来发现在“硬件和声音”中没有Realtek高清音频管理器,之后找到解决办法如下: 1. 找到Realtek高清音频 ...

  3. 出现 HTTP Status 500 - Servlet.init() for servlet springmvc threw exception 异常

    出现这种异常在网上搜了搜 ,大多数都是说jdk和tomcat版本的问题:而我前几天都是运行得好好的,今天就编写了代码一运行项目发现报了这个错误.后台仔细看了看错误信息.结果是在你的项目中有相同的req ...

  4. js实现左右自动滚动

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. MyBatis(8)——联表多对一的处理

    xml说明: <!--column不做限制,可以为任意表的字段,而property须为type 定义的pojo属性--> <resultMap id="唯一的标识" ...

  6. Linux常用命令英文全称与中文解释 (pwd、su、df、du等)

    https://blog.csdn.net/qq_40334837/article/details/83819735 Linux常用命令英文全称与中文解释 apt: Advanced Packagin ...

  7. 【visio】数据可视化 - 链接到外部数据

    编辑数据的时候,纯粹一个一个地手动输入,效率过低,visio提供了连接外部数据的功能,以加快数据导入,该功能也同时能够针对外部数据的改变,更新visio内部数据. 1. 创建外部源数据 visio支持 ...

  8. QQ发起聊天

    QQ推广 网址: http://shang.qq.com/v3/widget.html 一键加群 实例: <a target="_blank" href="//sh ...

  9. AngularJS请求数据提示resource from url not allowed by $sceDelegate policy

    AngularJS iframe跨域打开内容时报错 解决方案 使用  $sceDelegateProvider  配置跨域请求域名 config.js app.config(function($sce ...

  10. Fiddler修改http请求响应简单实例

    Fiddler是一个http调试代理,它能够记录并检查所有你的电脑和互联网之间的http通讯. 主要功能 设置断点,查看Fiddle说有的进出的数据(指cookie,html,js,css等文件,这些 ...