import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class JavaApplication14 {
public static void main(String[] args) {
try {
Document doc = Jsoup.connect("tanmoy_mahathir.makes.org/thimble/146").get();
String html= "<html><head></head>" + "<body><p>Parsed HTML into a doc."
+ "</p></body></html>";
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);
}
}
}
can anyone help me with jsoup code how can i parse just portion including paragraph so that just print
Hello ,World!
Nothing is impossible
clean. Creates a new, clean document, from the original dirty document, containing only elements allowed by the safelist. The original document is not modified. Only elements from the dirty document's body are used.
jsoup is a Java library for working with real-world HTML. It provides a very convenient API for fetching URLs and extracting and manipulating data, using the best of HTML5 DOM methods and CSS selectors. jsoup implements the WHATWG HTML5 specification, and parses HTML to the same DOM as modern browsers do.
For this small bit of html 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 see your link contains pretty much the same html you could then also replace the definition of doc
with
Document doc = Jsoup.connect("https://tanmoy_mahathir.makes.org/thimble/146").get();
UPDATE
Here is the full code that compiles and runs 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);
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With