簡體   English   中英

如何通過在 JAVA 中使用 jsoup 來獲取 html fie 中的第一個元素

[英]How to get just first element in html fie By using jsoup in JAVA

我想在 html 中獲得第一件事..如何獲得第一件..?

這是 HTML 文件的一部分,我在 JAVA 中使用了 Jsoup。

<div class="product-shelf-author contributors">by <a href="/s/%22Carol V. Aebersold%22? 
Ntk=P_key_Contributor_List&Ns=P_Sales_Rank&Ntx=mode+matchall">Carol V. Aebersold</a>, <a href="/s/%22 
Chanda A. Bell%22?Ntk=P_key_Contributor_List&Ns=P_Sales_Rank&Ntx=mode+matchall"> Chanda A. Bell</a> 
</div><div data-bv-show="inline_rating" data-bv-product-id="9780976990703" data-bv-seo="false"></div>
作者: Carol V. AebersoldChanda A. Bell

///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// ////////////////////////

Elements writer1 = doc.select("div.product-shelf-author");
Elements writer = writer1.select("a[href]");

如果我在 JAVA 中使用此電源線,“Chanaa A.Bell”也將添加到 Elements writer 中...

但我只想在“元素作家”中添加“Carol V.Aebersold”:((

Class Elements擴展ArrayList ,因此您可以獲得索引為 0 的第一個元素。

Elements writer1 = doc.select("div.product-shelf-author");
Elements writer = writer1.select("a[href]");
Element firstElement = writer.get(0);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM