added lua http user agent snippet
This commit is contained in:
parent
e1a5584a19
commit
afc7a690e3
3 changed files with 19 additions and 1 deletions
|
@ -648,6 +648,7 @@ function onTypeChange(node) {
|
|||
["HTTP POST", "local http = require(\"http\")\nlocal client = http.client()\n\nlocal request = http.request(\"POST\", \"http://httpbin.org/post\", \"{}\")\nlocal result, err = client:do_request(request)\nif err then\n table.insert(logs, err)\n error(err)\nend\nif not (result.code == 200) then\n table.insert(logs, err)\n error(err)\nend\n\ntable.insert(outputs, result.body)\n "],
|
||||
["HTTP Auth", "local http = require(\"http\")\nlocal client = http.client()\n\nlocal request = http.request(\"GET\", \"http://httpbin.org/basic-auth/gowatch/gowatch123\")\nrequest:set_basic_auth(\"gowatch\", \"gowatch123\")\nlocal result, err = client:do_request(request)\nif err then\n table.insert(logs, err)\n error(err)\nend\nif not (result.code == 200) then\n table.insert(logs, err)\n error(err)\nend\n\ntable.insert(outputs, result.body)\n "],
|
||||
["HTTP Bearer", "local http = require(\"http\")\nlocal client = http.client()\n\nlocal request = http.request(\"GET\", \"http://httpbin.org/bearer\")\nlocal token = \"gowatch123\"\nrequest:header_set(\"Authorization\", \"Bearer \" .. token)\nlocal result, err = client:do_request(request)\nif err then\n table.insert(logs, err)\n error(err)\nend\nif not (result.code == 200) then\n table.insert(logs, err)\n error(err)\nend\n\ntable.insert(outputs, result.body)\n "],
|
||||
["HTTP User Agent", "local http = require(\"http\")\nlocal agent = \"GoWatch Crawler\"\nlocal client = http.client({user_agent = agent})\n\nlocal request = http.request(\"GET\", \"http://httpbin.org/headers\")\nrequest:header_set(\"User-Agent\", agent)\nlocal result, err = client:do_request(request)\nif err then\n table.insert(logs, err)\n error(err)\nend\nif not (result.code == 200) then\n table.insert(logs, err)\n error(err)\nend\n\ntable.insert(outputs, result.body)\n "],
|
||||
["HTTP Proxy", "local http = require(\"http\")\nlocal client = http.client({ proxy = \"http://login:password@hostname.com\" })\n\nlocal request = http.request(\"GET\", \"https://api.ipify.org\")\nlocal result, err = client:do_request(request)\nif err then\n table.insert(logs, err)\n error(err)\nend\nif not (result.code == 200) then\n table.insert(logs, err)\n error(err)\nend\n\ntable.insert(outputs, result.body)\n "],
|
||||
["HTTP Browserless", "local http = require(\"http\")\nlocal client = http.client()\n\n# note \" for keys/values\nlocal data = '{\"url\": \"https://api.ipify.org\"}'\nlocal request = http.request(\"POST\", \"http://browserless:3000/content\", data)\nrequest:header_set(\"Content-Type\", \"application/json\")\nlocal result, err = client:do_request(request)\nif err then\n table.insert(logs, err)\n error(err)\nend\nif not (result.code == 200) then\n table.insert(logs, \"Response != 200 - \" .. result.code)\nend\n\ntable.insert(outputs, result.body) \n "],
|
||||
["XPath", "local xmlpath = require(\"xmlpath\")\n\nlocal query = \"//td[@class='price']\"\nlocal query, err = xmlpath.compile(query)\nif err then\n table.insert(logs, err)\n error(err)\nend\n\nfor i,input in pairs(inputs) do\n local node, err = xmlpath.load(input)\n if err then\n table.insert(logs, err)\n error(err)\n end\n local iter = query:iter(node)\n for k, v in pairs(iter) do\n table.insert(outputs, v:string())\n end\nend\n "],
|
||||
|
|
|
@ -695,6 +695,24 @@ if not (result.code == 200) then
|
|||
error(err)
|
||||
end
|
||||
|
||||
table.insert(outputs, result.body)
|
||||
`],
|
||||
["HTTP User Agent", `local http = require("http")
|
||||
local agent = "GoWatch Crawler"
|
||||
local client = http.client({user_agent = agent})
|
||||
|
||||
local request = http.request("GET", "http://httpbin.org/headers")
|
||||
request:header_set("User-Agent", agent)
|
||||
local result, err = client:do_request(request)
|
||||
if err then
|
||||
table.insert(logs, err)
|
||||
error(err)
|
||||
end
|
||||
if not (result.code == 200) then
|
||||
table.insert(logs, err)
|
||||
error(err)
|
||||
end
|
||||
|
||||
table.insert(outputs, result.body)
|
||||
`],
|
||||
["HTTP Proxy", `local http = require("http")
|
||||
|
|
1
todo.md
1
todo.md
|
@ -1,5 +1,4 @@
|
|||
# Todo
|
||||
- lua user agent snippet
|
||||
- import options add/clear
|
||||
- comments
|
||||
- safe escape {{ }} for pages
|
||||
|
|
Loading…
Add table
Reference in a new issue