This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
1vannn's profile picture

Take part of a webpage?

Started by 1vannn, 27 May 2013 - 08:40 PM
1vannn #1
Posted 27 May 2013 - 10:40 PM
Alright, say I have a list on a module on a Enjin forum website of the max player time on the server. How might I be able to get rid of everything else except the player name, and the top 5 times?
James0x57 #2
Posted 28 May 2013 - 01:18 AM
Unfortunately http://tekkitbyfifty.com/ catches computercraft http.get() requests as a robot and will not return the real HTML you'd need to parse.

If that wasn't the case, and the site gave you its normal html, then something close to this would work:


local html = (http.get("http://tekkitbyfifty.com/")).readAll();
local i = string.find(html.."", "minecraftservertopplayersonline", 1, true);
html = string.sub(html, i).."";

i = string.find(html, "</td>", 1, true);
html = string.sub(html, 1, i).."";

local ret = {};
local time = "";
local player = "";
i = string.find(html, "time", 1, true);
while i ~= nil do
    html = string.sub(html, i).."";
    i = string.find(html, ">", 1, true);
    html = string.sub(html, i+1).."";
    i = string.find(html, "<", 1, true);
    time = string.sub(html, 1, i).."";

    i = string.find(html, "name", 1, true);
    html = string.sub(html, i).."";
    i = string.find(html, ">", 1, true);
    html = string.sub(html, i+1).."";
    i = string.find(html, "<", 1, true);
    player = string.sub(html, 1, i).."";

    ret[#ret+1] = {player=player; time=time;};
    print(player..": "..time);

    i = string.find(html, "time", 1, true);
end