0
<div id="divEvents">

    <ul class="News_Title_Link">

    <li style="line-height:20px"><a href="/article/us-asia-storm-japan-idUSKBN1AO09Y" title="Now a tropical storm, Noru rakes Japan's main island">Now a tropical storm, Noru rakes Japan's main island</a> (21/03/2017 12:11)</li>

    <li style="line-height:20px"><a href="/article/us-southkorea-military-idUSKBN1AO0C9" title="South Korea's Moon taps Air Force chief to head Joint Chiefs of Staff">South Korea's Moon taps Air Force chief to head Joint Chiefs of Staff</a> (18/03/2015 17:16)</li>

I use jsoup to get the date and time, ex :"21/03/2017 12:11" but the output is "South Korea's Moon taps Air Force chief to head Joint Chiefs of Staff (17/03/2017 17:16)".

Here is my code

 Document doc = Jsoup.connect(url).get();
 Element time = doc.select("li").get(1);
 String text = time.text();

Can anyone help to fix the code to get only date and time.

Thank you.

2
  • 1
    maybe you wanted time.ownText() so as not to get the text of the sub-elements? Commented Aug 9, 2017 at 2:32
  • Thanks. time.ownText() works. Commented Aug 9, 2017 at 2:46

2 Answers 2

2

Try using time.ownText() in order to get the text of the selected <li> element while excluding the text of the <a> sub-element of <li>.

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

Comments

0

Element time = doc.select("li").get(1); Instead of using 1, place 0.

Element time = doc.select("li").get(0); //this will select the first li tag

1 Comment

I want to get time only not the whole text so i find out the correct code is time.ownText(). Anyway, thank you for your answer.

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.