我在编写一些Java代码以便在使用维基百科的文本上实现NLP任务。如何使用JSoup来提取维基百科文章的所有文本(例如http://en.wikipedia.org/wiki/Boston中的所有文本)?jsoup - 从维基百科文章中提取文本
回答
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()
。
为什么不呢?它应该,但它返回像标题或枚举项目符号。如果您只需要(英文)单词,您需要过滤一下,但我们不知道您的具体要求。 – 2012-02-06 13:18:26
我在你的代码中复制了你的代码,但它不工作。然而,在尝试您的解决方案之前,我已经自己完成了......并且解决方案也是类似的不过谢谢...现在我正在处理另一个问题! http://stackoverflow.com/questions/9160760/how-can-i-extract-specific-links-in-wikipedia-articles-using-jsoup#comment11521257_9160760 – Ema 2012-02-06 14:07:21
我从实时代码中取出这些行,所以它们应该至少运行。 – 2012-02-06 14:52:03
Document doc = Jsoup.connect("http://en.wikipedia.org/wiki/Boston").timeout(5000);
Element iamcontaningIDofintendedTAG= doc.select("#iamID") ;
System.out.println(iamcontaningIDofintendedTAG.toString());
OR
Elements iamcontaningCLASSofintendedTAG= doc.select(".iamCLASS") ;
System.out.println(iamcontaningCLASSofintendedTAG.toString());
Document doc = Jsoup.connect(url).get();
Elements paragraphs = doc.select(".mw-content-ltr p");
Element firstParagraph = paragraphs.first();
Element lastParagraph = paragraphs.last();
Element p;
int i=1;
p=firstParagraph;
System.out.println(p.text());
while (p!=lastParagraph){
p=paragraphs.get(i);
System.out.println(p.text());
i++;
}
- 1. jsoup - 如何从维基百科文章的文本中获取链接
- 2. 从维基百科文章(Python)中提取第一段
- 3. 从维基百科文章中提取Java关键字
- 4. 从维基百科文章中提取数据
- 5. PHP +维基百科:从维基百科文章的第一段获取内容?
- 6. 从维基百科取代文本
- 7. android:从维基百科文章显示标题和文本
- 8. 从文本中提取维基百科条目
- 9. 提取和解析维基百科文章
- 10. 获得维基百科文章概要
- 11. 隐藏维基百科文章反馈
- 12. 总结维基百科文章
- 13. 维基百科API,提取文本,包括链接的文本
- 14. 从维基百科中提取内容
- 15. 提取结构松散的维基百科文本。 html
- 16. 提取维基百科
- 17. 从维基百科转储提取并行文本
- 18. 如何从维基百科获取文章修订历史
- 19. 从维基百科获取文章XML转储 - 通过标题
- 20. 从维基百科获取文章的第一段
- 21. 维基百科的文章频率文章
- 22. 从维基百科API提取数据
- 23. 如何获取维基百科文章中使用Jsoup的其他文章的链接?
- 24. 从维基百科文章中删除我的名字
- 25. 脚本从维基百科
- 26. 为维基百科文章提供的人员的MQL
- 27. 从维基百科获取维基百科主题标题
- 28. 如何使用维基百科API获取维基百科文章信息框中的信息?
- 29. 获取维基百科文章的当前状态?
- 30. 获取维基百科文章的内容
是解析与有趣的问题'jsoup'部分的文本?因为如果不是的话,你应该使用'action = raw'参数来获取每个页面的源代码。例如http://en.wikipedia.org/w/index.php?title=Elephant&action=raw – beerbajay 2012-02-05 16:59:59
返回Wiki标记。 – 2012-02-05 17:30:42
使用它,它在维基百科服务器上也更加强大和安全:http://trulymadlywordly.blogspot.com/2011/03/creating-text-corpus-from-wikipedia.html – Maarten 2013-09-08 01:53:21