/** @author chaynes@indiana.edu */ public class EbertRecommends { public static final String URL = "http://rogerebert.suntimes.com/apps/" + "pbcs.dll/section?category=REVIEWS05"; public static final int FAIL = -1; /** * Get the text of Roger Ebert's recommendations page and print * a list of the recommended movie titles. This is done by searching * between the first occurrence of 'Ebert Recommends' and the next * '' for movie names. Names start after the first 'b>' after * 'href' and end with the following '<'. */ public static void main(String[] args) { String text = GetText.fromUrl(URL); if (text == null) { System.err.println("Could not get text."); return; } int begin = text.indexOf("Ebert Recommends") ; int endRecs = text.indexOf("", begin); while (true) { int i = text.indexOf("href", begin); if (i == FAIL || i > endRecs) break; begin = text.indexOf("b>", i) + 2; int end = text.indexOf("<", begin); String title = text.substring(begin, end); System.out.println(title); } } }