# HG changeset patch # User Nobuyasu Oshiro # Date 1380320353 -32400 # Node ID 18ba4378501eeab0bf774f865b7d2680bfb58ecd # Parent 7e9ce3e3d84a1598df64dbdccc0f8f7b8f5a0ba2 implemented getWinNum function diff -r 7e9ce3e3d84a -r 18ba4378501e http/win_rate.lua --- 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('(.-)') + 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 +