3

I am trying to get the src URL for the captcha from this website using jsoup. The problem is when I use inspect in chrome, it shows me the URL of captcha but when I access it using jsoup in my android project, the return html doesn't contain any img field and src that contain the link of captcha image. It is kind of hidden in html but only show when I use the inspect thing in chrome. I want to get the url so that I can download the captcha and show it in my imageview. Here is the link to the website.

https://cms.bahria.edu.pk/Logins/Student/ForgotPassword.aspx

enter image description here

and here is the html and as you can see it's not showing the img tags.

enter image description here

Here is the code I have written so far

 private class forgetpassword extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }

        @Override
        protected Void doInBackground(Void... voids) {
            try {
                Document document = Jsoup.connect("https://cms.bahria.edu.pk/Logins/Student/ForgotPassword.aspx").get();


                Element img = document.select("div#AspireCaptcha").first();

                if (img == null) {
                    throw new RuntimeException("Unable to locate image in ");
                }
                String imgSrc = img.absUrl("src");

                bitmaps = BitmapFactory.decodeStream((InputStream) new URL(imgSrc).getContent());


            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);
            imageView.setImageBitmap(bitmaps);
        }
    }

It would really helpful if you guys could guide me to solve this problem. I am really stuck at this problem for days.

Ebad Ali
  • 600
  • 1
  • 6
  • 29
  • 1
    it's most likely rendered using javascript after page loads. You would need to load page in a headless browser on your server to do it – charlietfl Oct 09 '16 at 23:25
  • @charlietfl Is there any other way to do? I don't have the server all I have is access to this website. – Ebad Ali Oct 09 '16 at 23:28
  • Doesn't make sense...you are running asp code on your server. That's where you would install a headless browser – charlietfl Oct 09 '16 at 23:30
  • Possible duplicate of [Android - Parse JS generated urls with JSOUP](http://stackoverflow.com/questions/39140121/android-parse-js-generated-urls-with-jsoup) – Frederic Klein Oct 10 '16 at 05:05
  • Use a WebView with enabled JavaScript (as a headless browser, without actually displaying the page) and a JavascriptInteface to receive the html source after JavaScript is processed, then parse the result with jsoup. Compare: http://stackoverflow.com/a/39174441/1661938 – Frederic Klein Oct 10 '16 at 05:07
  • if it's your concern yet , this problem will be solved if you use webview and adding JavaScriptInterface into it. – Hosein Haqiqian Jul 02 '19 at 12:02

0 Answers0