Some web pages have color backgrounds. Some web pages use images Grab the color
ID: 3622103 • Letter: S
Question
Some web pages have color backgrounds. Some web pages use images Grab the color of the background if it has a color, otherwise get the name of the image Here is an example of a black background color <body text = “#FFFFFF” bgcolor = “#000000”> return 000000 in this example Here is an example of a background with an image <body background = “Computer-Background.jpg”> return Computer-Background.jpg in this example If the page has neither, then return “no background specified” return no background specified in this example
Use this method below to enter a url and return the page source, make sure to use substring
public String openURL(String url) throws Exception { URL server = null; try { server = new URL(url); //connect to the target URL } catch (MalformedURLException m) { throw new Exception(m); }
BufferedReader in = null; try { in = new BufferedReader(new InputStreamReader(server.openStream())); //open a new stream buffer } catch (IOException i) { throw new Exception(i); }
String pageSource = "", SourceLine; try { while ((SourceLine = in.readLine()) != null) { //keep building the string until there is no more to read pageSource += SourceLine + " "; }
} catch (IOException i) { throw new Exception(i); }
try { in.close(); //close the connection to the server } catch (IOException i) { throw new Exception(i); } return pageSource; }