splash的使用之三har/json

splash的使用之三har/json

render.har

以har格式返回有关splash于网站交互的信息.包括有关请求,收到的响应,时间,标题等的信息.可以使用在线har查看器来可视化从该端点返回的信息,类似chrome开发工具中的”网络”标签.

当request_body和response_body选项分别设置为1时,包括请求和响应内容.

由于har格式规范缺少对二进制请求数据进行编码的方法,encoding因此包括非标准字段postData,类似于har响应中的相同名称字段,具有base64当请求主题如此编码时的值.

参数与render.html相同,另外还有以下内容:

request_body:int:可选
# 可能的值为1和0.为1时请求内容包含在har记录中.默认为0.
response_body:int:可选
# 可能的值为1和0.为1时响应内容包含在har记录中.
默认为0.

render.json

返回一个json编码的字典,其中包含有关JavaScript呈现 的网页信息可以包含基于传递参数的html/png和其他信息.

参数:与render.jpeg相同,加上以下内容:

html:integer:可选
# 是否在输出中包含html,可能的值为1(include)和0(exclude),默认为0.
png:integer:可选
# 是否在输出中包含png,可能的值为1(include)和0(exclude),默认为0.
jpeg:integer:可选
# 是否在输出中包含JPEG,可能的值为1(include)和0(exclude),默认为0.
iframes:integer:可选
# 是否在输出中包含有关子帧的信息,可能的值为1(include)和0(exclude),默认为0.
script:integer:可选
# 是否在输出中包含已执行的JavaScript final语句的结果,可能的值为1(include)和0(exclude),默认为0.
console:integer:可选
# 是否包含网页主框架的请求/响应的历史记录,可能的值为1(include)和0(exclude),默认为0.
history:integer:可选
# 是否包含网页主框架的请求/响应的历史内容,可能的值
是1(include)和0(exclude),默认为0.
# 使用它来获取http状态代码和标头,仅返回关于"主要"
请求/响应的信息.要获取有关所有请求和响应的信息,请使用har参数.
har:integer:可选
是否在输出中包含har,可能的值为1(include)和0(exclude),默认为0.如果打开,结果将包含har键下的render.har相同的数据.
默认情况下,不包括请求和响应内容,要启用每个选项,请分别使用request_body和response_body.
request_body:int:可选
# 可能的值为1和0.为1时请求内容包含在har中,默认为0.
# 当har和history均为0时,选项无效.
response_body:int:可选
# 可能的值为1和0.为1时响应内容包含在har中,默认为0.
# 当har和history均为0时,选项无效.

示例

默认情况下,返回url,请求url,页面标题和框架几何图形.

{
    "url": "http://crawlera.com/",
    "geometry": [0, 0, 640, 480],
    "requestedUrl": "http://crawlera.com/",
    "title": "Crawlera"
}

添加html=1将html添加到结果中:

{
    "url": "http://crawlera.com/",
    "geometry": [0, 0, 640, 480],
    "requestedUrl": "http://crawlera.com/",
    "html": "-->",
            "requestedUrl": "http://www.youtube.com/embed/lSJvVqDLOOs?version=3&rel=1&fs=1&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent",
            "childFrames": []
        }
    ],
    "requestedUrl": "http://scrapinghub.com/autoscraping.html"
}


与html不同,png会影响childFrames中的数据.



执行JavaScript代码时,将参数script=1添加到请求中以在结果中包含代码输出:



{
    "url": "http://crawlera.com/",
    "geometry": [0, 0, 640, 480],
    "requestedUrl": "http://crawlera.com/",
    "title": "Crawlera",
    "script": "result of script..."
}


JavaScript代码支持console.log()函数来记录消息,将console=1添加到请求中以在结果中包含控制台输出.



{
    "url": "http://crawlera.com/",
    "geometry": [0, 0, 640, 480],
    "requestedUrl": "http://crawlera.com/",
    "title": "Crawlera",
    "script": "result of script...",
    "console": ["first log message", "second log message", ...]
}


请求示例:

 full information curl 'http://localhost:8050/render.json?url=http://domain.com/page-with-iframes.html&png=1&html=1&iframes=1' HTML and meta information of page itself and all its iframes curl 'http://localhost:8050/render.json?url=http://domain.com/page-with-iframes.html&html=1&iframes=1' only meta information (like page/iframes titles and urls) curl 'http://localhost:8050/render.json?url=http://domain.com/page-with-iframes.html&iframes=1' render html and 320x240 thumbnail at once; do not return info about iframes curl 'http://localhost:8050/render.json?url=http://domain.com/page-with-iframes.html&html=1&png=1&width=320&height=240' Render page and execute simple Javascript function, display the js output curl -X POST -H 'content-type: application/javascript' \ -d 'function getAd(x){ return x; } getAd("abc");' \ 'http://localhost:8050/render.json?url=http://domain.com&script=1' Render page and execute simple Javascript function, display the js output and the console output curl -X POST -H 'content-type: application/javascript' \ -d 'function getAd(x){ return x; }; console.log("some log"); console.log("another log"); getAd("abc");' \ 'http://localhost:8050/render.json?url=http://domain.com&script=1&console=1'
上一篇
下一篇