一句話簡介: 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
幾包含了能想到的全部的庫,而且支持各類主流的操做系統,但我本人對其並不瞭解,必要時只有來研究下其英文文檔。