import java.util.*; import java.io.*; import java.net.*; public class getImages { public static void getImageURLs(String input1, String input2) throws Exception { try { int src=0, secondQuote=0; byte byteArray[] = new byte[4082]; String temp = new String(); String baseURL = "http://www.mrjameswright.com/", htmlFile="index.php", url = baseURL + htmlFile, proxy = "proxy.yourcompany.org", port = "8080", resetBaseURL = baseURL; if (!(input1.indexOf("http://") == -1 || input2.equals(""))) { baseURL = input1; htmlFile = input2; url = baseURL + htmlFile; } else { System.out.println("Invalid input!!!"); return; } URL server = new URL(url); Properties systemProperties = System.getProperties(); systemProperties.setProperty("http.proxyHost",proxy); systemProperties.setProperty("http.proxyPort",port); HttpURLConnection connection = (HttpURLConnection)server.openConnection(); // You might need to spoof some settings: browser (user-agent), referer, and operating system connection.setRequestProperty("user-agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows XP)"); connection.setRequestProperty("Referer","http://www.google.com"); connection.setRequestProperty("ua-os", "Windows XP"); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.connect(); System.out.println(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = in.readLine()) != null) { //System.out.println(line); while (line.indexOf("src=") > -1) { src= line.indexOf("src="); secondQuote= line.indexOf('"', line.indexOf('"', src)+1); if (line.indexOf("http://", src) == src+5) baseURL = ""; else { if (line.indexOf("/") == src+5) src++; baseURL = resetBaseURL; } // end of else //if (href > -1 ) System.out.println(baseURL + line.substring(href+6,secondQuote)); //System.out.println(line); //System.out.println(line.indexOf("http://",src)); //System.out.println("SRC: " +src+" 2ndQ: "+secondQuote+ " "+baseURL+line.substring(src+5,secondQuote)); downloadImage(baseURL+line.substring(src+5,secondQuote)); line = line.substring(secondQuote, line.length()); } // end of while loop } // end of while loop in.close(); } catch ( IOException e ) { e.printStackTrace(); } } // end of getImageURLs public static void downloadImage(String address) { String localFileName = address.substring(address.lastIndexOf("/")+1); OutputStream out = null; URLConnection conn = null; InputStream in = null; try { URL url = new URL(address); Properties systemProperties = System.getProperties(); systemProperties.setProperty("http.proxyHost","proxy.yourcompany.org"); systemProperties.setProperty("http.proxyPort","8080"); out = new BufferedOutputStream( new FileOutputStream(localFileName)); conn = url.openConnection(); in = conn.getInputStream(); byte[] buffer = new byte[1024]; int numRead; long numWritten = 0; while ((numRead = in.read(buffer)) != -1) { out.write(buffer, 0, numRead); numWritten += numRead; } System.out.println(localFileName + "\t" + numWritten); } catch (Exception e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } if (out != null) { out.close(); } } catch (IOException ioe) { } } } public static void main(String[] args) { try{ getImageURLs(args[0],args[1]); } catch (Exception e) { System.out.println("An error has occurred!!!"); } } // End of main }