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">&euro;</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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -