我对Java和Jsoup还是陌生的。我已经成功地使用Jsoup抓取了网站数据。但是,当前我正在打印搜索结果标题,它们全部返回一行。我想将结果嵌套在for循环中,以便搜索标题结果每行打印一次。
This is how the website is formatted:
<ul>
<li><span class ="title">Title 1<span></li>
<li><span class ="title">Title 2<span></li>
<li><span class ="title">Title 3<span></li>
</ul>
我的代码正在返回:标题1标题2标题3
My Java code:
public class WebScrape {
public static void main (String [] args) throws Exception {
final Document document = Jsoup.connect("website.com").get();
String searchResultsTitle = document.select("span[class=title]").text();
System.out.println(searchResultsTitle);
}
}