Extract Span tag data using Jsoup

懵懂的女人 提交于 2019-12-23 11:54:22

问题


I am trying to extract the specific content in html using Jsoup. Below is the sample html content.

<html xmlns="http://www.w3.org/1999/xhtml">
 <head> 
 </head>
 <body class="">
  <div class="shop-section line bmargin10 tmargin10">
   <div class="price-section fksk-price-section unit">
    <div class="price-table">
     <div class="line" itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
      <div class="price-save">
       <span class="label-td"><span class="label fksk-label">Price :</span></span>
      </div>
      <span class="price final-price our fksk-our" id="fk-mprod-our-id">Rs.<span class="small-font"> </span>11990</span>
     </div>
     <meta itemprop="price" content="Rs. 11990" />
     <meta itemprop="priceCurrency" content="INR" />
     <div class="our-price-desc fksk-our-price-desc">
      <small>(Prices are inclusive of all taxes)</small>
     </div>
    </div>
   </div>
  </div>
 </body>
</html>

I got the required output using below command:

document.select(".price-table").select(".line").select("span").get(2).text()

Looks like its lengthy. Can't i able to directly get using span class ("price final-price our fksk-our")?

Any help regarding the same?


回答1:


Does this not work for you? Not sure why you're arbitrarily starting at price-table.

doc.select("span[class=price final-price our fksk-our]").text();

If not, it should be pretty close. Look at JSoup's selector syntax; it is very powerful.



来源:https://stackoverflow.com/questions/9446263/extract-span-tag-data-using-jsoup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!