简体   繁体   中英

Parsing HTML table using Jsoup Scala

I would like to extract the Deck Name, that is "Jund" from the table below. I am using Jsoup for the purpose. I am already able to extract the required table using the class in which the table contains but I am not able to extract the deck name.

<table style="width:100%;padding:35px;" class="table_deck"> 
 <tbody>
  <tr> 
   <th style="width:66%;" align="left" colspan="2"> Reid Duke playing Jund </th> 
   <th scope="position"> Position: 18 </th> 
  </tr> 
  <tr> 
   <th style="width:66%;" align="left" colspan="2"> Deck Name: Jund </th> 
   <th scope="hide"> Sideboard </th> 
  </tr> 

 </tbody>
</table>

I am using following code to get the required table present in desired class. I am new to scala and your help would be great for me.

val jsoup = Jsoup.parse(content)
val table = jsoup.select("table[class=table_deck]").first()

You can use pseudo selector contains: Jsoup.parse(html).select("th:contains(Deck Name)").text()

https://jsoup.org/cookbook/extracting-data/selector-syntax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM