Java 从Jsoup中的HTML文件提取文本信息

Java 从Jsoup中的HTML文件提取文本信息,java,html,jsoup,Java,Html,Jsoup,在我正在编写的一段代码中,我需要从网页中获取一些信息。此信息因登录的用户而异 我试图在下面的代码中获取两条信息,分别标记为name和id number <tr> <td align="right"><b><label for="name" id="lblname">Name:</label></b> &nbsp;</td> <td>*name here*</td>

在我正在编写的一段代码中,我需要从网页中获取一些信息。此信息因登录的用户而异

我试图在下面的代码中获取两条信息,分别标记为name和id number

<tr> 
  <td align="right"><b><label for="name" id="lblname">Name:</label></b> &nbsp;</td> 
  <td>*name here*</td> 
  <td align="right"><b><label for="ident" id="lblident">Local ID</label>:</b> &nbsp;</td> 
  <td>*id number here*</td> 
</tr> 
它的所有输出都是代码的这一部分:

<label for="name" id="lblname">Name:</label>
名称:

要在此处定义HTML文件的名称部分,我需要做什么?

在获取

后,您可能会使用正则表达式来提取所需的内容。您可以使用Jsoup来提取所需的确切元素,例如:

// select the "name" <td>
Element name = doc.select("td:has(label#lblname) + td").first();

// select the "id" <td>
Element id = doc.select("td:has(label#lblident) + td").first();

// print out the text 
System.out.println(name.text());
System.out.println(id.text());
// select the "name" <td>
Element name = doc.select("td:has(label#lblname) + td").first();

// select the "id" <td>
Element id = doc.select("td:has(label#lblident) + td").first();

// print out the text 
System.out.println(name.text());
System.out.println(id.text());
*name here*
*id number here*