Simon Hostettler Simon Hostettler - 1 month ago 9x
HTML Question

Get whole html code - Java?

I wanted to write a code that prints out the whole html code from a website, so I could get information about a certain player. My Problem now is:


public class DownloadPage {

public static void main(String[] args) throws IOException {

URL url = new URL("");

URLConnection con = url.openConnection();
InputStream is =con.getInputStream();

BufferedReader br = new BufferedReader(new InputStreamReader(is));

String line = null;

// read each line and write to System.out
while ((line = br.readLine()) != null) {

When i run this code it only prints the overview:

<head><title>302 Found</title></head>
<body bgcolor="white">
<center><h1>302 Found</h1></center>

Id be very grateful if you could explain me how I can print the whole html code, and what I did wrong.


Three problems:

  1. What you get from is a redirection to This redirection is used to force users to connect by HTTPS.

  2. If you try to get data from you will get an SSL exeception. You can see more about it on: StackOverflow question. If you resolve this (fe. by accepting all certificates, not recommended in production) you will get HTML file, but it wouldn't be useful, because there is no player data on it.

  3. The data you actually want to get is retrieved by Javascript and AJAX calls. This is a great information for you, because you if you resolve problems with SSL you can get player data as JSON file, by calling fe.

Then you can use any JSON parser fe. Gson to easily get values you want.

Note: To view JSON file in nice and readable form you can use this site or some plugin for your browser like JSONView for Chrome.