Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Getting Join Date?

Asked by 8 years ago

I'm unsure of how to do this, I'm not great with using the HTTPService.

My code looks at the moment:

local id = 1
local httpservice = game:GetService("HttpService")
local url = "http://rproxy.pw/users/" ..id.. "/profile"
local cut = [[<p class="stat%-title">Forum Posts</p><p class="rbx%-lead">%d+</p>]]

2 answers

Log in to vote
4
Answered by
gskw 1046 Moderation Voter
8 years ago

You want to use the string.match method.
First of all, you want to use parenthesis in your "cut", or your string pattern to tell which part you want to grab (I'm also going to fix it for you here since it was designed to grab the forum posts):

local cut = [[<p class="stat%-title">Join Date</p>%S+<p class="rbx%-lead">(.-)</p>]]

So. what's going on here?
Well, here's an example of how the HTML would look:

...
            <p class="stat-title">Join Date</p>
            <p class="rbx-lead">1/5/2013</p>
...

Well, obviously you want to extract "1/5/2013" here. The most obvious solution is to use the pattern <p class="rbx%-lead">(.-)</p>. % means that the following character will be "escaped", so that Lua ignores its special behavior. (.-) means "match as few characters as possible", which would match 1/5/2013 since it also wants to find the <p class... string before (.-) and </p> after it.
But here's the problem: There are other things matching that pattern, too, such as the place visits and forum posts. You'll have to specify what you REALLY want to find.
That's why I added the beginning: <p class="stat%-title">Join Date</p>%S+
This obviously matches the code for the label. %S+ means that it should also match all the whitespace, since there are newlines and stuff after it.
Now, you'll have to request the page and match it:

local id = 1
local httpservice = game:GetService("HttpService")
local url = "http://rproxy.pw/users/" ..id.. "/profile"
local html = httpservice:GetAsync(url) -- added
local cut = [[<p class="stat%-title">Join Date</p>%S+<p class="rbx%-lead">(.-)</p>]] -- changed
local joindate = html:match(cut);

For further information:
* http://wiki.roblox.com/index.php?title=API:Class/HttpService
* http://lua-users.org/wiki/PatternsTutorial
* http://lua-users.org/wiki/StringLibraryTutorial

Also, I haven't tested the code, but it should work.

Ad
Log in to vote
-2
Answered by 8 years ago
function getJoinDate(id)
    local link = "http://www.rproxy.pw/users/" ..id.. "/profile";
    local cut = [[<p class="stat-title">Join Date</p><p class="rbx-lead">%.+</p>]];
    local serv = game.HttpService;
    local html;
    local success,msg = pcall(function()
        html = serv:GetAsync(link,false);
    end);
    if success then 
        --local find = html:match(cut);
        if html then
            print(html);
        else
            print("Cannot Get Join Date");
        end;
    else
        print("Cannot Get Join Date (Access denied to ROBLOX website)");
    end;
end;

getJoinDate(21467784);

The above code will go and copy the whole webpage. xD I did this and dropped it into notepad++ and searched for part of my join date (2011). It found this in there. So if you found a way to go and cut the join date out of it that should in theory work.

0
How do I get it to work? GullibleChapV2Alt 15 — 8y
0
I am having that same problem. I'm trying to figure it out, but sadly it seems like it doesn't work. Check my edited answer to see the code I tried to use to get it to work. MrLonely1221 701 — 8y
0
This prints out the whole webpage and the match string "cut" is incorrect anyway. gskw 1046 — 8y
0
I'm still getting 'nil'. GullibleChapV2Alt 15 — 8y
0
Thanks to whom ever down voted. This gets you close and I know the cut doesn't work. I did not come up with this code. This code does get you closer to having the join date though. You could possibly try a string.find(html, "Join Date</p><p id=\"rbx-lead\">%a+</p>") and see if it gets it. MrLonely1221 701 — 8y

Answer this question