INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / Микроблог / Thingiverse / RSS / GPG

Splash: how to change user-agent with Lua in Bash

№ 10157 В разделах: Programming Sysadmin от August 3rd, 2019,
В подшивках: , , ,

Before start install jq application, required to work with JSON, used to prepare lua script for sending to Splash API.

Create file named splash.lua

function main(splash, args)
  splash:set_user_agent('Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20')
  splash:set_viewport_size(800, 600)
  splash:go('https://www.whatismybrowser.com/')
  splash:wait(0.5)
  return splash:png()
end

Create bash script run.sh

#!/bin/bash

JSON="{\"lua_source\":$(jq -Rs . < script.lua)}"

curl -s -X POST -H "Content-Type: application/json" -d "${JSON}" \
   "http://192.168.1.9:5009/execute" -o out.png

Check result image

Нет комментариев »

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Яндекс.Метрика

Fortune cookie: I Know A Joke!!