简体   繁体   English

如何通过在 JAVA 中使用 jsoup 来获取 html fie 中的第一个元素

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

I want to get just first thing in html.. How to get just first one..?我想在 html 中获得第一件事..如何获得第一件..?

this is part of HTML file and I used Jsoup in JAVA.这是 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>
by Carol V. Aebersold , Chanda A. Bell 作者: Carol V. AebersoldChanda A. Bell

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

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

if I use this cord in JAVA "Chanaa A.Belll" is aslo added in Elements writer...如果我在 JAVA 中使用此电源线,“Chanaa A.Bell”也将添加到 Elements writer 中...

but I just want to add just "Carol V.Aebersold" in "Element writer":((但我只想在“元素作家”中添加“Carol V.Aebersold”:((

Class Elements extends ArrayList , so you can get first element which index is 0. 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