Reputation: 97
So I have this code the gets the href from a class. But I want to make it print all the hrefs that have the same class.
This is the part of my code that gets the href from that class.
Document doc = Jsoup.parse(file, null);
String links = doc.select("a.group-link-for-image").first().attr("abs:href");
System.out.println(links);
This is the output:
http://dogtime.com/dog-breeds/affenpinscher
I want to be able to print all the hrefs not just one that has the same class group-link-for-image
.
Thank you in advance.
Upvotes: 1
Views: 310
Reputation: 812
// First, find all elements that fit your criteria
Elements links = doc.select("a.group-link-for-image");
// Then, walk through the found elements and collect the information you want
for (Element link : links) {
System.out.println(link.attr("abs:href"));
}
The code snippet uses jsoup 1.11.2 API.
Upvotes: 1