Java Reference
In-Depth Information
der="0"></a>
</td><td valign="top">Heaton Research, Inc.<br>
HTTP Recipes Test Site
</td></tr>
</table>
<hr><p><small>[<a href="/">Home</a>:<a href="/1/">First Edition</
a>
:<a href="/1/3/">Chaper 3</a>]</small></p>
<h3>St. Louis, MO</h3>
The local time in St. Louis, MO is <b>Jun 27 2006 05:58:38 PM</b>.
<br><br><a href="cities.php">[Return to list of cities]</a><br>
<hr>
<p>Copyright 2006 by <a href="http://www.heatonresearch.com/">
Heaton Research, Inc.</a></p>
</BODY>
</HTML>
Look at the above listing and see if you can find the time and date for St. Louis? Did you
find it? It is the line about two-thirds of the way down that starts with the text “The local time
in St. Louis, MO is”. To extract this data we need to look at the two HTML tags that enclose
it. For this web page, the time and date are enclosed in the <b> and </b> tags.
The following example, shown in Listing 3.3, will download this data, and extract the date
and time information.
Listing 3.3: Get the Time in St. Louis (GetTime.java)
package com.heatonresearch.httprecipes.ch3.recipe2;
import java.io.*;
import java.net.*;
public class GetTime
{
/**
* The size of the download buffer.
*/
public static int BUFFER_SIZE = 8192;
/**
* This method downloads the specified URL into a Java
* String. This is a very simple method, that you can
* reused anytime you need to quickly grab all data from
Search WWH ::




Custom Search