Loading...
Logo
Processing Forum
Hi all, is there a way to pull all the images/videos out from a webpage that is NOT XML feed in processing?

Thanks!!

Replies(1)

With Jsoup you can get the HTML source of a website. After that, it's easy to get the images or video's. I believe the only exception is animated gif and certain video files like avi/wmv. Processing does not display those. You can however retrieve those files and store them on your computer and watch them outside of Processing.

Also, after some searching in this forum, i found : https://forum.processing.org/topic/load-image-from-web-13-7-2012



Copy code
  1. import org.jsoup.*;
  2. import org.jsoup.parser.*;
  3. import org.jsoup.select.*;
  4. import org.jsoup.nodes.*;
  5. Document doc;
  6. URL url;
  7. URI uri;
  8. void setup() {
  9.   println(extracturl("http://www.flickr.com/groups/landcape/pool/"));
  10. }
  11. String[] extracturl(String s) { 
  12.   try {
  13.     doc = Jsoup.connect(s).get();
  14.   }
  15.   catch (IOException ex) {
  16.     println(ex);
  17.   }
  18.   Elements imageElement = doc.select("img[src]");
  19.  
  20.   // remove everything except the url
  21.   String[] imgUrl = new String[imageElement.size()];
  22.   int count = 0;
  23.   for (Iterator<Element> i = imageElement.iterator(); i.hasNext();) {
  24.     Element e = i.next();
  25.     if (e.attr("src").contains("http"))
  26.       imgUrl[count++] = e.attr("src");
  27.     else { // retrieve the full url
  28.       try {
  29.         url = new URL(s);
  30.       }
  31.       catch (MalformedURLException ex) {
  32.         println(ex);
  33.       }
  34.       try {     
  35.         uri = url.toURI();
  36.       }
  37.       catch (URISyntaxException ex) {
  38.         println(ex);
  39.       }
  40.       imgUrl[count++] = uri.resolve(e.attr("src")).toString();
  41.     }   
  42.     e.remove();
  43.   }
  44.   return imgUrl;
  45. }