/************************************************************************* * * This enumerates lines in a text file and writes it to out.txt * *************************************************************************/ import java.util.*; import java.io.*; import java.net.*; public class ReadHTML { public static void main(String[] args) { Scanner scanner = null; String str ="http://finance.yahoo.com/q?s=goog"; try { URL url = new URL(str); scanner = new Scanner( url.openStream() ); } catch (IOException ioe) { System.err.println("Could not open " + str); System.exit(0); } String line = null; int p = -1; while(scanner.hasNextLine()) { line = scanner.nextLine(); if( (p = line.indexOf("Last Trade:")) != -1) break; } if(p == - 1) { System.out.println("cannot find quote"); System.exit(0); } line = line.substring(p); // that line looks like this one: // Last Trade: // 390.69 int right = line.indexOf(""); int left = line.lastIndexOf(">", right); System.out.println( line.substring(left+1, right) ); } }