I am trying to get the HTML code of a web page in Java, but I don't actually know how it should work. That is my thoughts:
public String getHTML(String pageAddress) throws Exception {
StringBuilder sb = new StringBuilder();
URL pageURL = new URL(pageAddress);
URLConnection uc = pageURL.openConnection();
BufferedReader br = new BufferedReader(
new InputStreamReader(uc.getInputStream()) );
String inputLine;
try {
while ((inputLine = br.readLine()) != null) {
sb.append(inputLine);
}
} finally {
br.close();
}
return sb.toString();
}
When I call
getHTML("http://www.google.com");
It returns empty string. What's wrong?
Thank you in advance!
Aucun commentaire:
Enregistrer un commentaire