本文介绍了java jsoup删除新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
for (int x = 0; x < 8000; x += 50) {
Document doc = Jsoup.connect("localhost.com/"+x).get();
Elements links = doc.select("a[href]");
for (Element link: links) {
String text = link.text();
System.out.println(text);
}
}
}
}
哪个会给出这样的输出:
Which would give an output like this:
Adrian Riven
HalfSugar No Ice
Yassuo
Amandadog
P1 Sloosh
是否有删除空行的方法?所以它看起来像这样的输出:
Is there anyway to remove the empty lines? so it'd look like this as the output:
Adrian Riven
HalfSugar No Ice
Yassuo
Amandadog
P1 Sloosh
我尝试过text.replace("\ n",");text.replaceAll("\ r?\ n",")
i've triedtext.replace("\n", "");text.replaceAll("\r?\n", "")
像这样编辑,这对我不起作用没有尝试其他人
Edit like this, this did not work for meDidnt try the other one
Elements links = doc.select("a[href]");
for (Element link: links) {
Document docs = Jsoup.parse(String.valueOf(links));
docs.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
String text = link.text()+link.text();
System.out.println(text.replace("Show More", ""));
示例html:
</td>
<td class="SummonerName Cell">
<a href="/summoner/userName=Cris" class="Link">Cris</a>
</td>
<td class="TierRank Cell">Challenger</td>
<td class="LP Cell">1,137 LP</td>
<td class="TeamName Cell">
Apex Gaming
</td>
<td class="RatioGraph Cell">
<div class="WinRatioGraph">
<div class="Graph">
推荐答案
此技巧对我有用:
Document doc = Jsoup.connect("localhost.com").get();
Elements links = doc.select("a[href]");
for (Element link : links) {
if (!link.text().isEmpty())
System.out.println(link.text());
}
这篇关于java jsoup删除新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!