有没有办法解析
<a href="/summoner/userName=Huhi" class="Link">Huhi</a>
in html:
<a href="/summoner/userName=Huhi" class="Link">Huhi</a>
<a href="/summoner/userName=Huhi" class="Link">White</a>
<a href="/summoner/userName=Huhi" class="Link">Angle</a>
输出:
Huhi
White
Angle
答案 0 :(得分:1)
创建您的文档并获取所有[href]链接,遍历这些链接并获取它们包含的文本。像这样:
Document doc = Jsoup.connect(url).get();
Elements links = doc.select("a[href]");
for (Element link : links) {
String text = link.text();
}
答案 1 :(得分:1)
您只需选择a
并重复elements
并打印
String html ="<a href=\"/summoner/userName=Huhi\" class=\"Link\">Huhi</a>\n" +
"<a href=\"/summoner/userName=Huhi\" class=\"Link\">White</a>\n" +
"<a href=\"/summoner/userName=Huhi\" class=\"Link\">Angle</a>";
Document doc = Jsoup.parse(html);
Elements links = doc.select("a");
for (Element link : links) {
System.out.println(link.text());
}
如需进一步参考,请查看此链接selector-syntax