Mercurial > hg > Members > nobuyasu > Lua
changeset 6:18ba4378501e
implemented getWinNum function
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 28 Sep 2013 07:19:13 +0900 |
parents | 7e9ce3e3d84a |
children | ec8638157982 |
files | http/win_rate.lua |
diffstat | 1 files changed, 28 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/http/win_rate.lua Sat Sep 28 06:54:59 2013 +0900 +++ b/http/win_rate.lua Sat Sep 28 07:19:13 2013 +0900 @@ -1,15 +1,15 @@ package.path = '../?.lua;./?.lua;' .. package.path -local xml = require("xmlSimple").newParser() local io = require("io") local http = require("socket.http") local ltn12 = require("ltn12") -local url = "http://www.lolking.net/summoner/na/41645712#history" +local baseUrl = "http://www.lolking.net" +local userUrl = "/summoner/na/41645712" local request = {} -b, c, h = http.request +local b, c, h = http.request { - url = url, + url = baseUrl..userUrl, method = "GET", sink = ltn12.sink.table(request) } @@ -25,7 +25,7 @@ if (href == nil) then userInfo[j] = { name = j, - href = url + href = userUrl } else userInfo[name] = { @@ -38,5 +38,27 @@ if (count > 2) then break end end -for i,v in pairs(userInfo) do print(i,v) end +function getWinNum(url) + local request = {} + local b, c, h = http.request + { + url = url, + method = "GET", + sink = ltn12.sink.table(request) + } + local xmlString = table.concat(request) + local winNum = xmlString:match('<td class="lifetime_stats_val" style="">(.-)</td>') + return winNum +end +for i,v in pairs(userInfo) do + local userName = i + local userTable = v + local userUrl = v["href"] + userTable['win'] = getWinNum(baseUrl..userUrl) +end + +for i,v in pairs(userInfo) do + print(i.." "..v['win']) +end +