From 561c249eb03d205f671df2b77a8d60905e555cca Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Sun, 9 Oct 2022 18:26:04 +0800 Subject: [PATCH] update script --- demo/lang/lua/2_webpage_extract.lua | 24 ++++++------------------ demo/lang/lua/3_http_interface_call.lua | 25 ++++++------------------- 2 files changed, 12 insertions(+), 37 deletions(-) diff --git a/demo/lang/lua/2_webpage_extract.lua b/demo/lang/lua/2_webpage_extract.lua index a4d36c9b..5c6595b5 100755 --- a/demo/lang/lua/2_webpage_extract.lua +++ b/demo/lang/lua/2_webpage_extract.lua @@ -6,25 +6,13 @@ pid=0 1. Load web page from url http://xxx 2. Retrieve img element zt-logo.png in html -3. Check img exist >> `.*.png` +3. Check img exist >> `必应` ]] -local http = require("socket.http") -- need luasocket library (luarocks install luasocket) -local ltn12 = require("ltn12") +require("socket") +local https = require("ssl.https") -- need luasocket, luasec modules +local body, code, headers, status = https.request("https://cn.bing.com") -function http.get(u) - local t = {} - local r, c, h = http.request{ - url = u, - sink = ltn12.sink.table(t)} - return r, c, h, table.concat(t) -end - -r,c,h,body = http.get("http://max.demo.zentao.net/user-login-Lw==.html") -if c~= 200 then - print("ERR: " .. c) -else - _, _, src = string.find(body, "") - print(src) -end +_, _, src = string.find(body, "(.-)") +print(src) diff --git a/demo/lang/lua/3_http_interface_call.lua b/demo/lang/lua/3_http_interface_call.lua index 039d6a56..68fba558 100755 --- a/demo/lang/lua/3_http_interface_call.lua +++ b/demo/lang/lua/3_http_interface_call.lua @@ -6,26 +6,13 @@ pid=0 1. Send a request to interface http://xxx 2. Retrieve sessionID field from response json - 3. Check its format >> `^[a-z0-9]{26}` + 3. Check its format >> `^[a-z0-9]{8}` ]] -local http = require("socket.http") -- need luasocket library (luarocks install luasocket) -local ltn12 = require("ltn12") +require("socket") +local https = require("ssl.https") -- need luasocket, luasec modules +local body, code, headers, status = https.request("https://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1") -function http.get(u) - local t = {} - local r, c, h = http.request{ - url = u, - sink = ltn12.sink.table(t) - } - return r, c, h, table.concat(t) -end - -r, c, h,body = http.get("http://max.demo.zentao.net/pms/?mode=getconfig") -if c~= 200 then - print("ERR: " .. c) -else - _, _, src = string.find(body, '"sessionID":"(.-)"') - print(src) -end +_, _, src = string.find(body, '"startdate":"(.-)"') +print(src) -- GitLab