0

I'm trying to get an element from a page into a variable

    String url = "http://www.aaaaaaa.com"; 
    Document document = Jsoup.connect(url).get();
    String value = document.body().select("").get(0).text();

how to get this into the value

<div class="clock-text">12:10:13 pm</div>

2 Answers 2

1

If you know the element you're trying to retrieve will always have the class clock-text then you have to change the last line to:


String value = document.body().select(".clock-text").get(0).text()

JSoup's select method works with CSS queries.

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

Comments

1

Selector based on div with class name clock-text

Elements element = document.select("div.clock-text").first(); 

The first matched element, or null if contents is empty.

String value = element.text();

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.