gpt4 book ai didi

java - Jsoup从字符串解析

转载 作者:行者123 更新时间:2023-12-01 13:38:07 27 4
gpt4 key购买 nike

我是使用 Jsoup 的新手,我在从 div 获取文本值(类名文本作为字符串)时遇到问题。这是 a 想要废弃的字符串。

<body>
<div class="details ">
<div class="title turquoise2">
AAC-Olympia
</div>
<div class="subhead turquoise2">
Correspondentie-adres:
</div>
<div class="text">
Rijdt 37
<br /> 6631AP HORSSEN
<br /> 0487-541339
</div>
<div class="subhead turquoise2">
Accommodatie:
</div>
<div class="text">
Sportpark De Polenkamp
<br /> Bredestraat 3
<br /> 6631BC HORSSEN
<br /> 0487-541339
</div>
<div class="subhead turquoise2">
Opgericht:
</div>
<div class="text">
01-07-2011
</div>
<div class="subhead turquoise2">
Tenue:
</div>
<div class="text">
Shirt: Wit
<br /> Broek: Zwart
<br /> Kousen: Zwart
</div>
<div class="subhead turquoise2">
Regio:
</div>
<div class="text">
Veldregio: Regio 4 veld
<br /> Zaalregio:
</div>
<div class="subhead turquoise2">
Info:
</div>
<div class="text">
Relatienummer: NXTG36Z
<br /> Email:
<a href="mailto:janberg37@Caiway.nl">janberg37@Caiway.nl</a>
<br /> Website:
<a href="http://www.aac-olympia.nl">http://www.aac-olympia.nl</a>
<br /> District: Oost
</div>
<div class="subhead turquoise2">
Klasse(s):
</div>
<div class="text">
Klasse za:
<br /> Klasse zon: 5e klasse
<br /> Klasse zaal:
<br /> Junioren: Nee
<br /> Pupillen: Nee
<br /> Vrouwen: Nee
<br /> G-Voetbal: Nee
</div>
<div class="text">
<a href="http://downloadcentrum.knvb.nl/sportlink/knvb/document/matrix%20verenigingen%20district%20oost?id=55988">Overzicht indeling district Oost</a>
</div>
</div>
<div class="details details-functionaris">
<div class="title turquoise2">
AAC-Olympia
</div>
<div class="voorzitter">
</div>
<div class="secretaris">
</div>
<div class="penningmeester">
</div>
<div class="functionarissen">
</div>
</div>
</body>

我想从第二个 div 中获取类名文本,以下信息分开,我尝试了以下代码,但给了我空字符串,

Element Adres = finalDocument.getElementsByClass("text").get(1);
String AllTextValue = Adres.text();//This give me all information from the div

但我想要将所有 4 个文本值分开,

String firstText =  For this one i have no ieee what i need to do
String SecondText = Adres.getElementsByTag("br").get(0).text();//Returns Empty value
String ThirdText = Adres.getElementsByTag("br").get(1).text();//Returns Empty value
String FourthText = Adres.getElementsByTag("br").get(2).text();//returns Empty value

有人可以帮助我吗?非常感谢。

最佳答案

Elements 实现了 List 接口(interface),因此只需使用:

Elements Email = finalDocument.getElementsByTag("a");
String emailAddress = Email.get(0).text();

命名Elements对象Email有点误导。我推荐以下重构代码:

Elements anchors = finalDocument.getElementsByTag("a");
String email = anchors.get(0).text();

关于java - Jsoup从字符串解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21088620/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com