如何将jsoup文档另存为文本文件 [英] How to save a jsoup document as text file
本文介绍了如何将jsoup文档另存为文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将网页上的所有可读单词保存到一个文本文档中,而忽略html标记. 使用JSoup解析网页上的所有单词,我唯一的猜测是如何通过代码元素将真实单词与代码分开.
I am trying to save all of the readable words on a web page into one text document while ignoring html markup. Using JSoup to parse all of the words on a webpage, my only guess of how to seperate the real words from the code is through elements.
是否可以将jsoup文档的多个元素转换为文本文件?
Is it possible to convert multiple elements of the jsoup document into a text file?
即:
Elements titles = doc.select("title");
Elements paragraphs = doc.select("p");
Elements links = doc.select("a[href]");
Elements smallText = doc.select("a");
当前通过以下方式将解析另存为文档:
Currently saving the parse as a document with:
Document doc = Jsoup.connect("https:// (enter a url)").get();
推荐答案
简单方法
Document doc = Jsoup.connect("https:// (enter a url)").get();
BufferedWriter writer = null;
try
{
writer = new BufferedWriter( new FileWriter("d://test.txt"));
writer.write(doc.toString());
}
catch ( IOException e)
{
}
这篇关于如何将jsoup文档另存为文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文