【发布时间】:2018-06-11 13:54:39
【问题描述】:
您好,我正在使用 Jsoup 抓取一个 html 页面,我有 2 个 div 并排在一起:
<div class="time_head">... </div>
<div class="blockfix">... </div>
我需要获取第一个time_head,然后将其放入其中.. 来自第一个blockfix 的所有元素,依此类推。
到目前为止我尝试了什么:
Elements time_heads = doc.select("time_head");
for (Element time_head : time_heads) {
String the_time_head = Jsoup.parse(String.valueOf(time_head.getElementsByClass("time_head"))).text();
Log.i("the_time_head ", " Hz: "+the_time_head);
}
Elements blockfixs = doc.select("blockfix");
for (Element blockfix : blockfixs) {
String the_blockfix = Jsoup.parse(String.valueOf(time_head.getElementsByClass("blockfix"))).text();
Log.i("the_blockfix ", " Hz: "+the_blockfix);
}
我需要这样的结果:
time_head1:
---- blockfix elemts1
---- blockfix elemts2
---- blockfix elemts3
time_head2:
---- blockfix elemts1
---- blockfix elemts2
---- blockfix elemts3
【问题讨论】:
-
我不确定您要达到的目标。您能否发布带有实际输入和预期输出的示例?
-
我已经用输出更新了我的问题.. 输入 2 div 彼此相邻
标签: java android web-scraping jsoup