/* Daniel Shiffman               *//* Programming from A to Z       *//* Spring 2006                   *//* http://www.shiffman.net       *//* daniel.shiffman@nyu.edu       *//* Parsing HTML Example          */package basics;import java.io.IOException;import java.util.regex.Matcher;import java.util.regex.Pattern;import a2z.A2ZUrlReader;public class WeatherGrabberHTML {    public static void main(String[] args) throws IOException {    	A2ZUrlReader urlreader = new A2ZUrlReader("http://weather.yahoo.com/forecast/USNY0996.html");        String html = urlreader.getContent();                // Yucky yucky HTML looks like this, we want to search for 37 & 25        // High:</font>&nbsp;<b><font size="3" face="Arial">37&deg;</font></b><br>        // Low:</font>&nbsp;<b><font size="3" face="Arial">25&deg;</font></b>                // Grab high temperature        String high = regexTextBetween(html,"High:</font>&nbsp;<b><font size=\"3\" face=\"Arial\">","&deg;");        System.out.println("The high for today is: " + high + " degrees.");                // Grab low temperature        String low = regexTextBetween(html,"Low:</font>&nbsp;<b><font size=\"3\" face=\"Arial\">","&deg;");        System.out.println("The low for today is: " + low + " degrees.");        }        public static String regexTextBetween(String s, String startRegex, String endRegex) {        String bigRegex = startRegex + "(.*?)" + endRegex;        Pattern p = Pattern.compile(bigRegex);        Matcher m = p.matcher(s);        if (m.find()) {            return m.group(1);        } else {            return "oops!";        }    }    }