Reputation: 740
I want to fetch content from a website, such as title
and src
attributes of the images. Can any one help me out to achieve this.
Upvotes: 0
Views: 720
Reputation: 8100
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) {
e.printStackTrace();
}
}
}
Upvotes: 2