jsoup-从Wikipedia文章中提取文本 [英] jsoup - extract text from wikipedia article

查看:109
本文介绍了jsoup-从Wikipedia文章中提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些Java代码,以便使用Wikipedia在文本上实现NLP任务.如何使用JSoup提取Wikipedia文章的所有文本(例如 http://中的所有文本en.wikipedia.org/wiki/波士顿)?

I'm writing some Java code in order to realize NLP tasks upon texts using Wikipedia. How can I use JSoup to extract all the text of a Wikipedia article (for example all the text in http://en.wikipedia.org/wiki/Boston)?

推荐答案

Document doc = Jsoup.connect("http://en.wikipedia.org/wiki/Boston").get();
Element contentDiv = doc.select("div[id=content]").first();
contentDiv.toString(); // The result

您当然可以通过这种方式检索格式化的内容.如果您想要原始"内容,则可以使用Jsoup.clean过滤结果或使用调用contentDiv.text().

You retrieve formatted content this way, of course. If you want "raw" content you can filter the result with Jsoup.clean or use the call contentDiv.text().

这篇关于jsoup-从Wikipedia文章中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆