lua打开浏览器并加载网页_Lua访问网页
示例
例子,實(shí)現(xiàn)https方式,登錄網(wǎng)站,訪問(wèn)某個(gè)網(wǎng)頁(yè),修改其中參數(shù)的功能。其中xx應(yīng)用時(shí)候需要修改。
require("curl")
local ipList =
{
"192.168.1.1",
"192.168.1.1",
}
--登陸
function loginWeb(ip)
c = curl.easy_init()
c:setopt(curl.OPT_SSL_VERIFYHOST, 0);
c:setopt(curl.OPT_SSL_VERIFYPEER, 0);
c:setopt(curl.OPT_URL, "https://"..ip.."/")
c:setopt(curl.OPT_POSTFIELDS, "Username=admin&Password=admin&Frm_Logintoken=&action=login")
c:setopt(curl.OPT_WRITEFUNCTION, function(buffer)
--print(buffer)
--print("\r\n---------------------------\r\n");
return #buffer
end)
c:perform()
end
--訪問(wèn)頁(yè)面
function accessPage(ip)
c = curl.easy_init()
c:setopt(curl.OPT_SSL_VERIFYHOST, 0);
c:setopt(curl.OPT_SSL_VERIFYPEER, 0);
c:setopt(curl.OPT_URL, "https://"..ip.."/xxpage.html")
c:setopt(curl.OPT_WRITEFUNCTION, function(buffer)
--print(buffer)
--print("\r\n---------------------------\r\n");
return #buffer
end)
c:perform()
end
--設(shè)置參數(shù)
function setParameter(ip, file)
c = curl.easy_init()
c:setopt(curl.OPT_SSL_VERIFYHOST, 0);
c:setopt(curl.OPT_SSL_VERIFYPEER, 0);
c:setopt(curl.OPT_URL, "https://"..ip.."/xx.php")
c:setopt(curl.OPT_POSTFIELDS, "DaylightSavingsUsed=1&Dscp=-1")
local htmlTable = {}
c:setopt(curl.OPT_WRITEFUNCTION, function(buffer)
--print(buffer)
--print("\r\n---------------------------\r\n");
table.insert(htmlTable, buffer)
return #buffer
end)
c:perform()
local htmlStr = table.concat(htmlTable);
local resultBuff = "";
if string.match(htmlStr, "SUCC") ~= nil then
resultBuff = ip.." config OK\r\n";
print(resultBuff)
file:write(resultBuff);
else
resultBuff = ip.." config NOK\r\n";
print(resultBuff)
file:write(resultBuff);
end
end
local file = io.open(".\\result.txt", "w+");
for key,ip in ipairs(ipList) do
loginWeb(ip);
accessPage(ip);
openLightSave(ip, file);
end
file:close();
print("Done")
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的lua打开浏览器并加载网页_Lua访问网页的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: jpa 自定义sql if_Spring
- 下一篇: 设计一个具有大纯时延时间的一阶惯性环节的