Example #1
0
 public static void connect(ImageCrawlerController controller) throws IOException {
   // System.out.println("Downloading to " + controller.getFolderPath());
   Document doc = Jsoup.connect(controller.getAddress()).get();
   Elements images = doc.select("img[src~=(?i)\\.(png|jpe?g|gif)]");
   for (Element image : images) {
     String src = image.absUrl("src");
     controller.updateView();
     downloadImg(controller, src);
   }
 }
Example #2
0
 private static void downloadImg(ImageCrawlerController controller, String src)
     throws IOException {
   int indexname = src.lastIndexOf("/");
   String name = src.substring(indexname + 1, src.length());
   URL url = new URL(src);
   InputStream in = url.openStream();
   OutputStream out =
       new BufferedOutputStream(new FileOutputStream(controller.getFolderPath() + "/" + name));
   for (int i; (i = in.read()) != -1; ) {
     out.write(i);
   }
   out.close();
   in.close();
 }