一句话简介: html
在windows平台使用Lua脚本读取指定URL的内容,并写入本地文件系统。该功能纠结了好久,终于搞定了,主要缘由仍是对Lua脚本的库不熟悉。 windows
言归正转, socket
运行环境:windows 7 ui
Lua版本:lua5.1 lua
依赖库:luasocket-2.0.2 for windows, url
源代码: 操作系统
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的库网址: .net
http://luaforge.net/projects/ code
几包含了能想到的全部的库,而且支持各类主流的操做系统,但我本人对其并不了解,必要时只有来研究下其英文文档。