andyqee andyqee - 10 days ago 7
HTML Question

what method in jsoup can return the modified html?

When I parse the html file(stored in native) with jsoup. I have modified some elements in the html file,so I want to save the modified html, and replace the old one?

Do any body know which method in jsoup can do the job?

Thank you so much!!!

Answer

You could write the contents of either

document.toString() 

or

document.outerHtml()

to file, where document is got from

Document document = Jsoup.connect("http://...").get();
// any document modifications...

like so:

BufferedWriter htmlWriter = 
     new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
htmlWriter.write(document.toString());
Comments