D
D
Daeamon2015-06-14 17:30:41
Java
Daeamon, 2015-06-14 17:30:41

How to parse an image using java and jsoup?

Help please, I'm trying to parse an image from the page, but throws an exception on the line
Document doc = connection.url(" w3bsit3-dns.com/forum/index.php? ").get();
What am I doing wrong?

mContext = context;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.login, null);

        username_edit = (EditText) mView.findViewById(R.id.username_edit);
        captcha_edit = (EditText) mView.findViewById(R.id.captcha_edit);
        captcha_image = (ImageView) mView.findViewById(R.id.captcha_image);
        password_edit = (EditText) mView.findViewById(R.id.password_edit);
        privacy_checkbox = (CheckBox) mView.findViewById(R.id.privacy_checkbox);

        String ClassName = "ipbtable";
        try {
            String url = "http://4pda.ru/forum/index.php?act=Login&CODE=01";
            Connection connection=Jsoup.connect(url);
            connection.method(Connection.Method.GET);
            connection.referrer("http%3A%2F%2F4pda.ru%2Fforum%2Findex.php%3F");
            connection.ignoreHttpErrors(true);
            connection.timeout(1000);
            connection.data("act", "login");
            Connection.Response res = connection.execute();
            Document doc = connection.url("http://4pda.ru/forum/index.php?").get();

            Elements wrapper =  doc.select(ClassName).eq(0);
            Elements img =  wrapper.select("img").eq(0);
            String imageUrlStr = img.attr("src");
            Bitmap mIcon11 = null;

            URL newUrl = new URL(imageUrlStr);
            URLConnection urlConn =  newUrl.openConnection();
            InputStream stream = urlConn.getInputStream();

            mIcon11 = BitmapFactory.decodeStream(stream);
            captcha_image.setImageBitmap(mIcon11);

        } catch (Exception e) {

            e.printStackTrace();

        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IceJOKER, 2015-06-14
@Daeamon

You also need to add logs to give an accurate answer.
In your case, I believe that the problem is that you are trying to load data into the MainThread, the Internet connection, as well as resource-intensive tasks, must be moved to a separate thread.

P
permishin, 2020-02-04
@permishin

this is how I do
Document doc = Jsoup.connect(" https://www.vamsvet.ru/catalog/section/svetilniki ").get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question