Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Retrieving data from a webpage

Author
Message
SamKM
15
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 11th Jan 2014 23:01
Hey guys,
Just wondering, how would I grab content from a webpage? By content I don't mean files, I'm trying to grab the actual text on the webpage as a string, which is probably a lot harder... To be specific, I'm looking for a way to grab the time in UTC as a string from http://www.worldtimeserver.com/current_time_in_UTC.aspx
I've read a few threads about 'urlmon.dll' relating to getting data from websites, but to be honest I have no idea how to use it, or even if it's what I'm looking for... So, any suggestions?
Thanks!
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 12th Jan 2014 00:06
DownloadFileA in urlmon.dll will download a webpage as the resulting html source that is displayed by your browser. You will have to parse the file yourself to extract text from it.
For something like that it would be relatively easy; just look through the text yourself and look for a pattern that occurs immediately before the time and that is unique in the source. Then search for that pattern it in the downloaded source and extract the time that follows immediately after it (you may need to have another pattern that occurs immediately after the time so that you can determine when you should stop reading characters too, in case the time isn't always displayed as 6 characters or similar).


"Why do programmers get Halloween and Christmas mixed up?"
SamKM
15
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 12th Jan 2014 00:38
Thanks, I'll try that when I get the chance
MonoCoder
19
Years of Service
User Offline
Joined: 4th Dec 2005
Location: england
Posted: 12th Jan 2014 15:16
You've probably already considered this, but be aware that this approach holds only so long as that page at that name continues to exist (and is up at the time of request), and in its current form and structure. So if the site underwent a radical design overhaul, the old assumption about where to look for the time could break down.

I had a look about for ways you might get such a time more directly from a server, but at a glance it seems a bit complicated... so if your program is only taking hints from the site and not depending on it, you probably needn't worry.
SamKM
15
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 12th Jan 2014 22:27 Edited at: 12th Jan 2014 22:28
Good point Mono! The only way I can think of helping that is having it check against a backup server, in case the first one is down or they've reorganised it... Hopefully it won't be a problem too often

Login to post a reply

Server time is: 2025-05-15 14:35:22
Your offset time is: 2025-05-15 14:35:22