I got stuck on this problem: I need to get time and date from page presnycas.eu (to sync). Date is fine, but I cannot get the time. The problem is that when I call IdHTTP.Get(..) method, as a result I get the HTML of the page, but the time is missing. Like this:
<div class="boxik">
<table style="text-align: left; width: 700px; height: 116px;" border="0" cellpadding="2" cellspacing="0">
<tbody>
<tr>
<td style="width: 400px;" colspan="1" rowspan="5">
<div class="hodinyhlavni">
<span id="servertime"></span>
// This is where the time should be - when viewed with
// developer tools in Chrome, it does show the time
// (picture here http://img684.imageshack.us/img684/166/pagem.png)
</div>
</td>
<td style="width: 0px;">
07.07.2011
</td>
Now I am using an awkward approach – I load a TWebBrowser and then call
Time:=StrToTime(WebBrowser1.OleObject.Document.GetElementByID('servertime').innerhtml);
but well, it’s rather slow and I would rather not use the TWebBrowser at all.
So, how can I get the innerhtml of an element with a call of function?
Thanks in advance
The most important part of this answer would be “you need to understand HTML and JavaScript and figure out how the site works”. Open the web site, right-click and do “Show Source”. You’ll notice this at the top:
That looks like the time, and in my case, the time is correct but not adjusted to MY time zone. You can easily grab the plain HTML using Indy, and apparently that’s enough. This quick code sample shows you how to grab the HTML and parse the date and time using a little piece of RegEx. If you’re on Delphi XE, you’ll have to replace the
TPerlRegExclass name and thePerlRegExunit name to whatever XE wants. If you’re on older Delphi, that’s no excuse to NOT use RegEx! Download TPerlRegEx, it’s free and compatible with the XE stuff.