A
A
AKhorevich2015-07-15 13:25:53
Java
AKhorevich, 2015-07-15 13:25:53

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));






        }
    }

How to fix this problem? In addition, there are still problems with spaces in the link. (Hands would tear off the webmaster).
vnViS.pngLink to normal image 1
zzHMK.pngLink to normal image 2

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
programmerjava, 2015-07-16
@programmerjava

String imgSrc = myImage.attr("src");
if(imgSrc.equals("")) continue;
// удаляет пробелы
imgSrc = imgSrc.replace(" ","");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question