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

How would I retrieve some info from a website with HTTPService?

Asked by
iKobi 0
8 years ago

I need to get the time to print once from a website, but all I have is this. I'm new to HTTPService; need some guidance.

hs = game:GetService("HttpService")
test = hs:GetAsync("http://time.is/New_York", true)
0
you would need to look at the api for the time.is scottmike0 40 — 8y
0
I could set you up an API that returns the current time, shouldn't take long if you want. addictedroblox1414 166 — 8y

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

For the sake of solving this problem, I will answer your question. But you need to know that if you want to get the current time, you should use os.time or tick

To start, know that using the GetAsync function will return you the entire website's HTML markup. That being said, you must know what to look for in that mess of a string.

I've taken a look at the site you're trying to retrieve the time from. As you can see here, the div that holds the time has an id tag of "twd".

Now that you know what to look for, you can use the string.gmatch function to pick out your time. To do this, you need to use some string patterns:

  • <div id="twd"> will locate the div
  • ........ will locate the 8 possible characters for the time
local hs = game:GetService("HttpService") --HttpService
local test = hs:GetAsync("http://time.is/New_York", true) --Web info
local pattern = [[<div id="twd">........]] --Pattern to capture time

for i in test:gmatch(pattern) do 
    --'>' is the div's ending, '.+' gets everything after
    local capture = i:gmatch(">.+")
    --gmatch is an iterator function, you have to call it again.
    capture = capture();
    --'capture' is inclusive of the div's ending
    -- so get everything after the first character.
    print(capture:sub(2)) 
end
Ad

Answer this question