一句话简介:
在windows平台使用Lua脚本读取指定URL的内容,并写入本地文件系统。该功能纠结了很久,终于搞定了,主要原因还是对Lua脚本的库不熟悉。
言归正转,
运行环境:windows 7
Lua版本:lua5.1
依赖库:luasocket-2.0.2 for windows,
源代码:
http = require("socket.http")
function readFromURL()
local url = "http://www.baidu.com";
local ret = http.request(url);
print("ok");
local htmlFile = io.open("d:/baidu.html", "w");
print("writing file");
if(htmlFile) then
htmlFile:write(ret);
htmlFile:close();
end
end
readFromURL();
推荐一个非常好的Lua的库网址:
几包含了能想到的所有的库,并且支持各种主流的操作系统,但我本人对其并不了解,必要时只有来研究下其英文文档。