如何用Lua编写实现复杂流程的长尾词模拟登录脚本?
- 内容介绍
- 文章标签
- 相关推荐
本文共计330个文字,预计阅读时间需要2分钟。
我们的应用程序需要使用Lua从网站获取一些数据。但网站需要身份验证(如谷歌的登录方式)。我正在尝试使用LuaSocket库,但找不到完整的代码示例,因此只知道需要做什么。
我们的应用程序需要使用Lua从网站获取一些数据.但网站需要身份验证(如谷歌的登录方法).我正在尝试使用LuaSocket库,但是我找不到完整的代码示例,所以我只知道自己需要做什么.
我知道requestb.in/创建自己的.在浏览器中打开requestb.in/vbpkxivb?inspect以查看程序发送的数据.不要向此服务发送真实的登录名和密码!
require 'socket.requestb.in/vbpkxivb"; method = "POST"; headers = { ["Content-Type"] = "application/x-www-form-urlencoded"; ["Content-Length"] = #request_body; }; source = ltn12.source.string(request_body); sink = ltn12.sink.table(response_body); } print("Status:", res and "OK" or "FAILED") print("HTTP code:", code) print("Response headers:") if type(response_headers) == "table" then for k, v in pairs(response_headers) do print(k, ":", v) end else -- Would be nil, if there is an error print("Not a table:", type(response_headers)) end print("Response body:") if type(response_body) == "table" then print(table.concat(response_body)) else -- Would be nil, if there is an error print("Not a table:", type(response_body)) end print("Done dumping response")
预期产量:
Status: OK HTTP code: 200 Response headers: date : Sat, 23 Jun 2012 07:49:13 GMT content-type : text/html; charset=utf-8 connection : Close content-length : 3 Response body: ok Done dumping response
本文共计330个文字,预计阅读时间需要2分钟。
我们的应用程序需要使用Lua从网站获取一些数据。但网站需要身份验证(如谷歌的登录方式)。我正在尝试使用LuaSocket库,但找不到完整的代码示例,因此只知道需要做什么。
我们的应用程序需要使用Lua从网站获取一些数据.但网站需要身份验证(如谷歌的登录方法).我正在尝试使用LuaSocket库,但是我找不到完整的代码示例,所以我只知道自己需要做什么.
我知道requestb.in/创建自己的.在浏览器中打开requestb.in/vbpkxivb?inspect以查看程序发送的数据.不要向此服务发送真实的登录名和密码!
require 'socket.requestb.in/vbpkxivb"; method = "POST"; headers = { ["Content-Type"] = "application/x-www-form-urlencoded"; ["Content-Length"] = #request_body; }; source = ltn12.source.string(request_body); sink = ltn12.sink.table(response_body); } print("Status:", res and "OK" or "FAILED") print("HTTP code:", code) print("Response headers:") if type(response_headers) == "table" then for k, v in pairs(response_headers) do print(k, ":", v) end else -- Would be nil, if there is an error print("Not a table:", type(response_headers)) end print("Response body:") if type(response_body) == "table" then print(table.concat(response_body)) else -- Would be nil, if there is an error print("Not a table:", type(response_body)) end print("Done dumping response")
预期产量:
Status: OK HTTP code: 200 Response headers: date : Sat, 23 Jun 2012 07:49:13 GMT content-type : text/html; charset=utf-8 connection : Close content-length : 3 Response body: ok Done dumping response

