How to count the number of div using jsoup ?

Counting the number of div:

Code block:

[java]Elements all_divs = doc.getElementsByTag("div");
System.out.println(all_divs.size());[/java]

Output:

Gives the total number of div tag present in the webpage.

Sample Program:

[java]
import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class JavadomainParse {

public static void main(String[] args) throws IOException {
String url ="http://www.ngdeveloper.com";
Document doc = Jsoup.connect(url).get();
Elements all_divs = doc.getElementsByTag("div");
System.out.println(all_divs.size());
}
}
[/java]

Output:

271

Thanks for reading this post………….!!!

Leave a Reply