Answer the question
In order to leave comments, you need to log in
What to do with cyrillic and spaces in jsoup links?
Hey! I'm trying to parse images from a link, there periodically comes across something like
<img src="http://dog.org/sites/default/files/images/ главной!.thumbnail.jpg">
class ParsePage extends AsyncTask<String,Void,String>{
Document doc=null;
Elements names,imgs;
@Override
protected String doInBackground(String... params) {
try {
input = new URL("http://vao-priut.org/category/fotokatalog/sektor");
String link = String.valueOf(input);
doc = Jsoup.connect(link).get();
names = doc.select("table.col-3 div.views-field-title span.field-content a[href]");
imgs = doc.select("table.col-3 div.views-field-image-image span.field-content a img");
for (Element img : imgs) {
Element myImage = img;
String imgSrc = myImage.attr("src");
InputStream inp = new java.net.URL(imgSrc).openStream();
// Decode Bitmap
bitmap = BitmapFactory.decodeStream(inp);
allImages.add(bitmap);
}
for (Element name : names) {
list.add(name.text());
}
/* ProgressDialog mDialog = new ProgressDialog(getActivity());
mDialog.setMessage("Please wait...");
mDialog.setCancelable(false);
mDialog.show();*/
}catch(IOException e){
e.printStackTrace();
}
return text;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
sectorAdapter = new sector_adapter(getActivity());
c_grid.setAdapter(sectorAdapter);
image.setImageBitmap(allImages.get(0));
title.setText(list.get(0));
}
}
Answer the question
In order to leave comments, you need to log in
String imgSrc = myImage.attr("src");
if(imgSrc.equals("")) continue;
// удаляет пробелы
imgSrc = imgSrc.replace(" ","");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question