gpt4 book ai didi

java - 如何解析没有名字的 'div'?

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

使用 Jsoup:

Element movie_div = doc.select("div.movie").first();

我得到了这样的 HTML 代码:

<div class="movie"> 
<div>
<div>
<strong>Year:</strong> 2014
</div>
<div>
<strong>Country:</strong> USA
</div>
</div>
</div>

如何使用 jsoup 提取国家/地区和年份?

对于示例 html,我希望提取的值为 "2014""USA"

谢谢。

最佳答案

使用

Element e = doc.select("div.movie").first().child(0);
List<TextNode> textNodes = e.child(0).textNodes();
String year = textNodes.get(textNodes.size()-1).text().trim();
textNodes = e.child(1).textNodes();
String country = textNodes.get(textNodes.size()-1).text().trim();

关于java - 如何解析没有名字的 'div'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25362772/

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