Skip to content Skip to sidebar Skip to footer

Extract Strings Using Jsoup

I'm trying to get some name form class attribute within a website html page by using Jsoup Library, The problem is that i'm getting the elements by class using getElementsByClass(

Solution 1:

you can simply use split function to get an array from string

String arr[]=names.trim().split("\\s");

plus if you have spaces and tab combined between name then use

String arr[]=names.split("\\s+");

Update:

ArrayList<String>  name=newArrayList<String>();
      for (Elementoutput: html.body().getElementsByClass("name")) {
          name.add(output.text());
          }

example link

Output :

enter image description here

link to convert list to array

Post a Comment for "Extract Strings Using Jsoup"