How to count the number of div using jsoup ?

Counting the number of div:

Code block:

Elements all_divs = doc.getElementsByTag("div");
System.out.println(all_divs.size());

Output:

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

Sample Program:

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.javadomain.in";
		Document doc = Jsoup.connect(url).get();
		Elements all_divs = doc.getElementsByTag("div");
		System.out.println(all_divs.size());
	}
}

Output:

271

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

468 total views, 2 views today

Leave a Reply

Your email address will not be published. Required fields are marked *