Tuesday, February 23, 2010

Java - IMDB httpParser

public boolean checkURL(String url) {
boolean flag = false;
String line = null;
try {
//set up the http connection
HttpURLConnection httpCon = (HttpURLConnection)new URL(url).openConnection();
httpCon.setRequestProperty("User-agent", "Internet Explorer");
InputStream is = httpCon.getInputStream();
BufferedReader httpReader = new BufferedReader(new InputStreamReader(is,  "iso-8859-1"));

for (int i = 0; i < 8; i++) {
line = httpReader.readLine();
if (i == 7) {
System.out.println(line);
if (line.indexOf("") == -1) {
return true;
} else {
return false;
}
}
}

httpReader.close();
is.close();
httpCon.disconnect();

} catch (Exception e) {
System.out.println(e.toString());
}
return false;
}

No comments:

Post a Comment