/*
 * File: JSoupExample.java
 * ---------------------
 * This will read HTML from an explore courses URL
 * and list all of the course titles from that page!
 */

import java.io.*;
import java.net.*;


public class JSoupExample{
	
	public static void main(String[] args) {
		// Using Java's URL library to get code from explore courses
		String HTML = getSite();
		// Use JSoup
		
		// get title from webpage
		
		// get everything on the webpage with class="courseTitle"
		
		// print out data!
		
	}
	
	private static String getSite() {
		    InputStream is = null;
		    String HTML= "";

		    try {
		    	String exporeCoursesURL = "https://explorecourses.stanford.edu/search?view=catalog&filter-coursestatus-Active=on&page=0&catalog=&academicYear=&q=CS&collapse=";
		        URL url = new URL(exporeCoursesURL);
		        is = url.openStream();  // throws an IOException
		        BufferedReader br = new BufferedReader(new InputStreamReader(is));
		        
		        String line;
		        while ((line = br.readLine()) != null) {
		            HTML += line;
		        }
		    } catch (MalformedURLException mue) {
		         mue.printStackTrace();
		    } catch (IOException ioe) {
		         ioe.printStackTrace();
		    } finally {
		        try {
		            if (is != null) is.close();
		        } catch (IOException ioe) {
		            // nothing to see here
		        }
		    }
		    return HTML;
		
	}
}

