Hasan shaikh Hasan shaikh - 1 year ago 140
Java Question

How to extract image urls using jsoup

I want to fetch content from a website, such as

attributes of the images. Can any one help me out to achieve this.

Answer Source

Here is an example of reading all image src and title attributes:

public class Test {

    public static void main(String[] args) {
        try {
            Document doc = Jsoup.connect("http://www.golem.de/").get();
            Elements imageElements = doc.getElementsByTag("img");
            for (Element element : imageElements) {
                System.out.println("src: "+element.attr("src"));
                System.out.println("title: "+element.attr("title"));
        } catch (Exception e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download