我有一个 HTML 文件,其中一部分如下所示:
<a name="user_createtime"></a>
<p class="column">
<span class="coltitle">CreateTime</span> <span class="titleDesc"><span class='defPopupLink' onClick='popupDefinition(event, "datetime")'>datetime</span></span> <span class = "spaceandsize">(non-null)<sup><span class='glossaryLink' onclick="popupDefinition(event, '<b>non-null</b><br>The column cannot contain null values.')">?</span></sup></span>
<br>
<span class="desc">Timestamp when the object was created</span>
<a name="user_createuser"></a>
<p class="column">
<span class="coltitle">CreateUser</span> <span class="titleDesc">foreign key to <A HREF="User.html" TARGET="tableFrame">User</A></span>
<span class = "spaceandsize">(database column: CreateUserID)</span>
<br>
<span class="desc">User who created the object</span>
这样的Coltitle有很多。titleDesc 和 desc 类。
现在,如果我得到一个像“CreateTime”这样的输入字符串,我希望输出是:
CreateTime, datetime, Timestamp when the object was created
如果我得到一个输入字符串“CreateUser”,我希望输出是:
CreateUser, foreign key to User, User who created the object
我正在为此使用 Jsoup,并且已经做到了这一点:
Elements colElements = Jsoup.parse(html).getElementsByClass("coltitle").select("*");
System.out.println("your Col:");
for (Element element : colElements)
{
if(element.ownText().equalsIgnoreCase("CreateTime"))
System.out.println(element.text());
}
它只打印选定的 coltitle。如何解析相关类并获取它们的值?或者,他们甚至没有关系,我只是走错了路吗?有人可以帮我得到我想要的输出吗?