如何使用Jsoup从HTML获取“ img src链接”?

时间:2018-12-25 19:35:13

标签: html android-studio

我需要从HTML获取图像链接,该图像链接位于

之间(img)

MainActivity:

private void getWebsite() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                final StringBuilder builder = new StringBuilder();

            try {
                Document doc = Jsoup.connect(domain + "account").get();
                String title = doc.title();
                Elements elements  = doc.getElementsByClass("gravatar avatar avatar-120");

                builder.append(title).append("\n");

                for (Element e : elements ) {
                    builder.append("\n").append("Link : ").append(e.attr("src")) ;
                }
            } catch (IOException e) {
                builder.append("Error : ").append(e.getMessage()).append("\n");
            }

            Log.d("HTML", builder.toString());

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    //ProfileImgUrl = builder.toString();
                    result.setText(builder.toString());
               }
            });
        }
    }).start();
}

HTML:

other <img> tag
<a href="website link">
    <img src="image link" class="gravatar avatar avatar-120" etc...>
</a>
other <img> tag

我希望获得图像链接,但结果是一些其他文本。

0 个答案:

没有答案