我知道,如果我想用 Jsoup 打印链接和链接文本,我必须使用以下代码: Document doc = Jsoup.connect("https://en.wikipedia.org/wiki/Jsoup").get(); Elements links = doc.select("a[href]"); for (Element link : links) { System.out.println(link.attr("abs:href") + " - " + link.text()); }输出:(不完整) https://en.wikipedia.org/wiki/Jsoup#mw-head - Jump to navigation https://en.wikipedia.org/wiki/Jsoup#p-search - Jump to search https://en.wikipedia.org/wiki/Software_developer - Developer(s) https://en.wikipedia.org/wiki/Software_release_life_cycle - Stable release https://en.wikipedia.org/wiki/Jsoup#cite_note-1 - [1] https://en.wikipedia.org/wiki/Jsoup#cite_note-2 - [2] https://en.wikipedia.org/wiki/Repository_(version_control) - Repository https://github.com/jhy/jsoup - github.com/jhy/jsoup ...如果我想打印整个网页的文本,我必须使用以下代码:System.out.println(doc.body().text());输出:(不完整)jsoup 来自维基百科,免费的百科全书 跳转到导航 跳转到搜索 jsoup Java HTML Parser Developer(s) Jonathan Hedley 稳定版 1.11.3 [1] / 2018-04-15 [2] 存储库 github.com/jhy/jsoup.. .如何在没有链接文本的情况下打印文档的所有文本?输出我想要的:jsoup 来自维基百科,免费的百科全书 jsoup Java HTML Parser Jonathan Hedley 1.11.3 / 2018-04-15 ...
1 回答
开满天机
TA贡献1786条经验 获得超13个赞
JsoupElements有一个remove()方法。这应该从您的文档中删除链接。
Document doc = Jsoup.connect("https://en.wikipedia.org/wiki/Jsoup").get();
doc.select("a[href]").remove();
System.out.println(doc.body().text());
添加回答
举报
0/150
提交
取消
