Extract text within HTML <br> tags JSOUP

you can replace all <br> labels to \n symbol,the code example is shown below:

Document doc1 = Jsoup.parse(s);
Elements type1 = doc1.select("[class=\"style3\"]");
try {       
    String text =type1.first().html();
    text = text.replaceAll("<br>", "\n");
    System.out.println(text);
} catch (Exception e) {
    e.printStackTrace();
} 

or split the text to string array with <br> label

Document doc1 = Jsoup.parse(s);
Elements type1 = doc1.select("[class=\"style3\"]");
try {       
    String text =type1.first().html();
    String[] textSplitResult = text.split("<br>");
    if (null != textSplitResult) {
         for (String t : textSplitResult) {
             System.out.println(t);
         }
    }
} catch (Exception e) {
    e.printStackTrace();
} 

or use java8 lambda to output result

String text =type1.first().html();
String[] textSplitResult = text.split("<br>");
if (null != textSplitResult) {
    Arrays.stream(textSplitResult).peek((x) -> System.out.println(x)).count();
    //or Arrays.stream(textSplitResult).peek(System.out::println).count();
} 

The executing result:

PC / Van
$14 (Mon-Fri, excl PH)
$18 (Sat, Sun &amp; PH)

$70/Day(Mon-Fri, excl PH: Entry - 24:00)
$100/day (Sat, Sun &amp; PH: Entry - 24:00)

According to this question

How to split a string in Java

String text =type1.first.text();

String[] textArr = text.split("<br>");

Tags:

Html

Java

Jsoup