0
 <select id="list">
 <option value="0">First</option>
 <option value="1">Second</option>
 <option value="2">Third</option>
 </select>

For the above html content how do I make use of Jsoup to parse and get the text as

  First Second Third

When I use

Document doc=Jsoup.parse(HTMLText);
String text=doc.text();
System.out.println(text);

I get something like this

FirstSecondThird

1 Answer 1

1

You are already very close to the solution; just select the elements you need and get their text:

    final String html = " <select id=\"list\">\n"
            + " <option value=\"0\">First</option>\n"
            + " <option value=\"1\">Second</option>\n"
            + " <option value=\"2\">Third</option>\n"
            + " </select>";

    Document doc = Jsoup.parse(html);
    String text = doc.select("option").text(); // Select all 'option' tags --> get text of them

    System.out.println(text);

Result:

First Second Third
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.