For this little html snippet you just need to do
String html= "<html><head></head>" + "<body><p>Parsed HTML into a doc."+ +"</p></body></html>"; Document doc = Jsoup.parse(html); Elements paragraphs = doc.select("p"); for(Element p : paragraphs) System.out.println(p.text());
As I can see, your link contains pretty much the same html that you can also replace the doc definition with
Document doc = Jsoup.connect("https://tanmoy_mahathir.makes.org/thimble/146").get();
UPDATE
Here is the complete code that compiles and works just fine for me.
import java.io.IOException; import java.util.logging.*; import org.jsoup.*; import org.jsoup.nodes.*; import org.jsoup.select.*; public class JavaApplication14 { public static void main(String[] args) { try { String url = "https://tanmoy_mahathir.makes.org/thimble/146"; Document doc = Jsoup.connect(url).get(); Elements paragraphs = doc.select("p"); for(Element p : paragraphs) System.out.println(p.text()); } catch (IOException ex) { Logger.getLogger(JavaApplication14.class.getName()) .log(Level.SEVERE, null, ex); } } }
source share