我试图得到这个输出:
** * *电影名称:** * **
第二次世界大战
** * **演员表:** * ***
布拉德·皮特
Mireille Enos
James Badge Dale** * *电影名称:** * **
怪兽大学
** * **演员表:** * ***
Johnny Depp
Watsons Junior
<h2 itemprop="name">World War Z</h2>
<div class=info>1hr 56min - Rated PG13 - Action/Drama/Horror - English<br>
- Cast:
<span itemprop="actors">Brad Pitt</span>,
<span itemprop="actors">Mireille Enos</span>,
<span itemprop="actors">James Badge Dale</span>
</div>
<h2 itemprop="name">Monsters University</h2>
<div class=info>2hr 30min - Rated PG13 - Comedy - English<br>
- Cast:
<span itemprop="actors">Johnny Depp</span>,
<span itemprop="actors">Watsons Junior</span>
</div>
我试过这样做:
Elements movieTitle = doc.select("h2");
for (Element src : movieTitle) {
for (int i = 0; i < movieTitle.size(); ++i) {
title += movieTitle.get(i).text() + "\n";
}
break;
}
Elements casts = doc.select("span[itemprop=actors]");
for (Element sr : casts) {
for (int i = 0; i < casts.size(); ++i) {
cast += casts.get(i).text() + "\n";
}
break;
}
System.out.println("*************Movie Titles:************* \n" + title);
System.out.println("*************Casts:************* \n" + cast);
但输出是:
** * *电影名称:** * **
Z世界大战
怪兽大学
** * **演员表:** * ***
Brad Pitt
Mireille Enos
James Badge Dale
Johnny Depp
Watsons Junior
如何根据电影对演员进行分组?