I am using Jsoup to scrape a gallery of pictures from this italian website
in an AsyncTask with Jsoup i'm getting from the HTML all the urls of the images:
@Override
protected Void doInBackground(String... params) {
Document doc;
try {
ConnectivityManager conMgr = (ConnectivityManager) mActivity
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (conMgr.getActiveNetworkInfo() != null
&& conMgr.getActiveNetworkInfo().isAvailable()
&& conMgr.getActiveNetworkInfo().isConnected()) {
doc = Jsoup
.connect(urlReceivedToConnect)
.timeout(0).get();
Elements imgList = doc.getElementsByClass("phocagallery-box-file-third").select("img");
photoList = new ArrayList<String>();
ListIterator<Element> post = imgList.listIterator();
while (post.hasNext()) {
photoList.add(post.next().attr("abs:src"));
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
Then, in a costumized adapter, i'm taking this urlsList and i'm loading the images from the url that i'm putting in a gridView later:
private Drawable LoadImageFromURL(String url) {
try {
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (Exception e) {
System.out.println(e);
return null;
}
}
The problem is: some of the pictures are shown and are ok, but some others presents this error:
06-23 10:06:06.930: I/System.out(493): java.io.FileNotFoundException: http://www.italiaebraica.org/images/phocagallery/famiglia_levi/thumbs/phoca_thumb_m_Famiglia Levi 024.jpg
what's the problem? how can I get all the pictures in the right way? Please help, hope it is clear , i'm a junior developer!!