Splash API 调用
render.html
render.html 接口用于获取 JavaScript 渲染的页面的 HTML 代码,接口地址就是 Splash 的运行地址加此接口名称,例如http://localhost:8050/render.html。
http://0.0.0.0:8050/render.html?url=https://www.baidu.com&wait=5
http://0.0.0.0:8050 + render.html + url=https://www.baidu.com + wait=5import requests url = 'http://0.0.0.0:8050/render.html?url=https://www.baidu.com&wait=5'
response = requests.get(url)
print(response.text) # 运行
给此接口传递了一个url参数来指定渲染的URL,等待5秒钟,返回结果即页面渲染后的源代码。render.png
render.png 接口可以获取网页截图,通过 width 和 height 来控制宽高,它返回的是PNG 格式的图片二进制数据。
http://localhost:8050/render.png?url=https://www.jd.com&wait=5&width=1000&height=700
http://localhost:8050/render.png?url=https://www.jd.com&wait=5&width=1000&height=700
import requests url = 'http://localhost:8050/render.png?url=https://www.jd.com&wait=5&width=1000&height=700'
response = requests.get(url)
with open('taobao.png', 'wb') as f:
f.write(response.content)render.jpng
render.jpng 接口和 render.png 接口类似,只是多了个 quality 参数来设置图片的质量
render.har
render.har 接口用于获取页面加载的HAR数据,它的返回结果非常多,是一个 JSON 格式的数据,其中包含页面加载过程中的 HAR 数据。
import requests url = 'http://localhost:8050/render.har?url=https://www.jd.com&wait=5'
response = requests.get(url)
with open('jd1.json', 'wb') as f:
f.write(response.content) # 运行生成一个名为jd.json的文件execute
最强大的接口
import requests
from urllib.parse import quote # lua脚本
lua = '''
function main(splash)
return 'hello'
end
''' # quote()方法将lua脚本进行URL转码。lua_source作为参数传递
url = 'http://localhost:8050/execute?lua_source=' + quote(lua) response = requests.get(url)
print(response.text)
print(quote(lua)) # 输出:
hello
%0Afunction%20main%28splash%29%0A%20%20%20%20return%20%27hello%27%0Aend%0Aimport requests
from urllib.parse import quote lua = '''
function main(splash, args)
local treat = require("treat")
local response = splash:http_get("http://httpbin.org/get")
return {
html=treat.as_string(response.body),
url=response.url,
status=response.status
}
end
''' url = 'http://localhost:8050/execute?lua_source=' + quote(lua)
response = requests.get(url)
print(response.text)
print(quote(lua)) # 输出:
{"html": "{\n \"args\": {}, \n \"headers\": {\n \"Accept-Encoding\": \"gzip, deflate\", \n \"Accept-Language\": \"en,*\", \n \"Host\": \"httpbin.org\", \n \"User-Agent\": \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/602.1 (KHTML, like Gecko) splash Version/9.0 Safari/602.1\"\n }, \n \"origin\": \"120.239.195.171, 120.239.195.171\", \n \"url\": \"https://httpbin.org/get\"\n}\n", "status": 200, "url": "http://httpbin.org/get"}
%0Afunction%20main%28splash%2C%20args%29%0A%20%20local%20treat%20%3D%20require%28%22treat%22%29%0A%20%20local%20response%20%3D%20splash%3Ahttp_get%28%22http%3A//httpbin.org/get%22%29%0A%20%20%20%20return%20%7B%0A%20%20%20%20html%3Dtreat.as_string%28response.body%29%2C%0A%20%20%20%20url%3Dresponse.url%2C%0A%20%20%20%20status%3Dresponse.status%0A%20%20%20%20%7D%0Aend%0Afunction main(splash, args)
local treat = require("treat")
local response = splash:http_get("http://httpbin.org/get")
return {
html=treat.as_string(response.body),
url=response.url,
status=response.status
}
end // 输出:
Object
html: String (length )
{
"args": {},
"headers": {
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en,*",
"Host": "httpbin.org",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/602.1 (KHTML, like Gecko) splash Version/9.0 Safari/602.1"
},
"origin": "120.239.195.171, 120.239.195.171",
"url": "https://httpbin.org/get"
}
status:
url: "http://httpbin.org/get"Lua脚本
Splash API 调用的更多相关文章
- Vue.js——使用$.ajax和vue-resource实现OAuth的注册、登录、注销和API调用
概述 上一篇我们介绍了如何使用vue resource处理HTTP请求,结合服务端的REST API,就能够很容易地构建一个增删查改应用.这个应用始终遗留了一个问题,Web App在访问REST AP ...
- 信鸽推送 .NET (C#) 服务端 SDK rest api 调用库(v1.2)
信鸽推送 .NET 服务端 SDK rest api 调用库-介绍 该版本是基于信鸽推送v2版本的时候封装的,先拿出来与大家分享,封装还还凑合,不依赖其他http调用件,唯一依赖json序列化dll ...
- xmlrpc实现bugzilla api调用(无会话保持功能,单一接口请求)
xmlrpc实现bugzilla4 xmlrpc api调用(无会话保持功能,单一接口请求),如需会话保持,请参考我的另外一篇随笔(bugzilla4的xmlrpc接口api调用实现分享: xml ...
- FormatMessage与GetLastError配合使用,排查windows api调用过程中的错误
前一段时间在学习windows api调用过程中,遇到过一些调用错误或者程序没能显示预期的结果,或者直接出现vc运行时错误. 这对新手来说是司空见惯的事,因为不太熟悉难免会出错,出错的信息如果能显示很 ...
- Sphinx中文分词安装配置及API调用
这几天项目中需要重新做一个关于商品的全文搜索功能,于是想到了用Sphinx,因为需要中文分词,所以选择了Sphinx for chinese,当然你也可以选择coreseek,建议这两个中选择一个,暂 ...
- (36)老版和新版API调用
---------更新时间18:06 2016-09-18 星期日------- *前言 我用的是odoo8,但里面有相当多的api是以前版本,这时若我们自己开发的 插件采用新版本api,里面 ...
- Sphinx中文分词详细安装配置及API调用实战
这几天项目中需要重新做一个关于商品的全文搜索功能,于是想到了用Sphinx,因为需要中文分词,所以选择了Sphinx for chinese,当然你也可以选择coreseek,建议这两个中选择一个,暂 ...
- 控制ASP.NET Web API 调用频率与限流
ASP.NET MVC 实现 https://github.com/stefanprodan/MvcThrottle ASP.NET WEBAPI 实现 https://github.com/stef ...
- jquery api调用
本框架内置组件以及部分插件都可以通过jquery选择器进行API调用,支持链式操作,如下示例. <script type="text/javascript"> $(&q ...
随机推荐
- 【ADO.NET基础知识】SqlConnection、command、DataSet 、DataTable、dataAdapter
1.使用Connection连接数据库的步骤: (1).添加命名空间 System.Data.SqlClient(注意:初学者经常会忘记) (2)定义连接字符串.连接SQL Server 数据库时: ...
- [Note] Windows 10 Python 3.6.4 安装scrapy
直接使用pip install安装时会在安装Twisted出错,以下主要是解决Twisted的安装问题 1. 安装wheel pip install wheel 2. 安装Twisted 在Pytho ...
- Eclipse的Debug(一)
本文链接:https://blog.csdn.net/u011781521/article/details/55000066 http://blog.csdn.net/u010075335/ar ...
- Cannot access a disposed object in ASP.NET Core
Cannot access a disposed object in ASP.NET Core 楠木大叔 导航 常见原因 总结 对于.neter来说,在使用ASP.NET Core的过程中 ...
- display值的作用分别是什么?relative和absolute分别是相对谁定位的?
display值的作用分别是什么? none:元素隐藏,不占据位置 block:该元素显示为块级元素 inline:默认,该元素会被显示为内联元素 inline-block:行内块元素 list-it ...
- 深入理解Netty框架
前言 本文讨论的主题是Netty框架,本着3W原则 (What 是什么?->Why 为什么?->How 如何做?)来一步步探究Netty原理和本质以及运用场景. 了解基本名词 1.BIO. ...
- Jenkins部署(基于Linux)
1.安装JDK 我不列出来了,自行百度 java -version 2.安装tomcat (1)创建目录tomcat8 (2)导入tomcat文件到tomcat8目录中并解压 (3)启动tomcat ...
- Head First设计模式——观察者模式
1.气象监测应用,错误示范 有一个气象站,分别有三个装置:温度感应装置,湿度感应装置,气压感应装置.WeathData对象跟踪气象站数据,WeathData有MeasurmentsChanged()方 ...
- 机器学习实战_KNN(一)
[是什么] KNN 即 k_近邻算法(k- nearest neighbor) ,就是寻找K个邻居作为该样本的特征,近朱者赤,近墨者黑,你的邻居是什么特征,那么就认为你也具备该特征:核心公式为: 数据 ...
- XSS中的同源策略和跨域问题
转自 https://www.cnblogs.com/chaoyuehedy/p/5556557.html 1 同源策略 所谓同源策略,指的是浏览器对不同源的脚本或者文本的访问方式进行的限制.比如源a ...