dapwnerz
dapwnerz

Reputation: 1

java get element from webpage into variable

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>

Upvotes: 0

Views: 158

Answers (2)

Bishan
Bishan

Reputation: 15702

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();

Upvotes: 1

Frank Riccobono
Frank Riccobono

Reputation: 1063

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.

Upvotes: 1

Related Questions