简体   繁体   English

使用Jsoup Scala解析HTML表

[英]Parsing HTML table using Jsoup Scala

I would like to extract the Deck Name, that is "Jund" from the table below. 我想从下表中提取Deck Name,即“ Jund”。 I am using Jsoup for the purpose. 我正在为此目的使用Jsoup。 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. 我是scala的新手,您的帮助对我非常有用。

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() 您可以使用包含以下Jsoup.parse(html).select("th:contains(Deck Name)").text()伪选择器: Jsoup.parse(html).select("th:contains(Deck Name)").text()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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