Hi friends I need to open a url and display only the contents of the largest table in the web page using regular expressions......
I have written the code to open a url and display all the data between <table> tag and </table> tag in a web page.
Please help me correct the below code to find the largest table and display the content.
the code is.....
import java.net.*;
import java.io.*;
import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class ConnectionTest {
public static void main(
String[] args) {
try
{
URL yahoo = new URL("http://www.shopping.com");
URLConnection yahooConnection = yahoo.openConnection();
DataInputStream dis = new DataInputStream(yahooConnection.getInputStream());
String inputLine;
Pattern regexp = Pattern.compile("<table(.*?)</table>", Pattern.DOTALL);
while ((inputLine = dis.readLine()) != null) {
Matcher matcher = regexp.matcher(inputLine);
matcher.reset( inputLine ); //reset the input
if ( matcher.find() )
{
System.out.println(matcher.group());
}
}
dis.close();
} catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
} catch (IOException ioe) {
System.out.println("IOException: " + ioe);
}
}
}
Can anyone please help me?