Java use jsoup to get data from html

72 Views Asked by At

I use jsoup to get a document from a link

Document doc = Jsoup.connect(url).get();
Element price = doc.select("td#flc_close").first();

The result is

<td id="flc_close" nowrap align="right" class="td_buy"><span class="priceup2">7.70</span></td>

How can I get 7.7 above.

Any help is appreciated.

2

There are 2 best solutions below

0
Ailef On

You can use price.text() and this will select 7.70 in this case. If it is possible that the element contains text outside of the span and you only want to select what is inside the span, then:

price.select("span").text()

0
eThan_hunT On

You can use Jsoup selector with matches. It gives the exact result you needed

String price=doc.select("span.priceup2:matches(\d+.\d+)").text();

Thanks