[英]selecting a div tag with jsoup
嗨,我有2个div既显示日期又具有相同的名称。 我现在要专门显示第一个div,以后再显示第二个日期。 我尝试搜索,但是发现可以指定div name元素并通过它区分两个div。
(This is the first date which I want to display)
<div class="home-weather-sub-div-bar">
<span class="datetext1">Sunday, March 3, 2013 updated 14:45:00 CET</span>
</div>
(This is the second date which I want to display)
<div class="home-weather-sub-div-bar">
<span class="datetext1">Monday, March 4, 2013 until noon</span>
</div>
为了清楚起见,我尝试选择“ div.home-weather-sub-div-bar”和“ span.datetext1”,但仍会显示2013年3月3日(星期日),CET星期一更新14:45:00,然后它也将在2013年3月4日连接到同一行中午。
有什么帮助吗?
您可以选择具有给定属性的div
标签,然后选择所需的标签:
Document doc = ...
final Elements divs = doc.select("div.home-weather-sub-div-bar"); // Select the div-tags
Element firstDiv = divs.get(0); // get the first div
Element secondDiv = divs.get(1); // get the second div
System.out.println(firstDiv.text()); // print the text
System.out.println(secondDiv.text());
使用您发布的html,我得到以下输出:
Sunday, March 3, 2013 updated 14:45:00 CET
Monday, March 4, 2013 until noon
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.