java - How to get content from span with Jsoup -
i using jsoup html parser extract content html page.
<span class="mainprice reduced_"> <span class="oprice" data-test="preisartikel"> <span itemprop="price" content="68.00"><span class="opriceleft">68</span><span class="opriceseparator">,</span><span class="opriceright">00</span></span><span class="opricesymbol opricesymbolright">€</span>
i want extract content (68.00) , tried following:
elements price = doc.select("span.oprice"); string pricestring = price.text();
that doesn't work because class "oprice" occurs 44 times in page , string "pricestring" contains 44 different prices.
thank help.
try this:
//for 1 element element elements = document.select("span[content]").first(); system.out.println(elements.attr("content"));
if have multiple same span
//for multiple elements elements = document.select("span[content]"); (element element:elements){ system.out.println(element.attr("content")); }
output: 68.00
on top of check jsoupselector reference.
Comments
Post a Comment