0

I have found some code for extracting image link from html img tag. It uses Html Java library and uses certain method fromHtml.

I have pulled html code from some RSS feed and I want to extract and display image. I have accomplished that whit code bellow but I think that this is not elegant solution at all:

Html.fromHtml(html, new Html.ImageGetter() {
            @Override
            public Drawable getDrawable(final String source) {
                Drawable d = null;
                Glide.with(mContext)
                        .load(source)
                        .into(img);
                sImgUrl = source;
                return d;
            }
        }, null);

Is it possible to extract this 'source' string without overriding getDrawable()?

Ivan Z.
  • 59
  • 1
  • 10

1 Answers1

1

You can use JSoup Lib to do it manually like this.

String html = "<html>your html code goes here</html>";

Document doc = Jsoup.parse(html);
Elements image = doc.getElementsByTag("img");

 for (Element el : image) {
   String src = el.absUrl("src");
   System.out.println("src attribute is : "+src);
 }

and do your stuff with glide

this is refer for this answer

z.io
  • 166
  • 4