Saket Sinha Saket Sinha - 2 months ago 8x
Java Question

I need to use jsoup selector for more than one p tags

Hi i have an html code suppose,

<P>This is Stack overflow</p>
<p>This is stack overflow2</p>

I need to select all the
tags from the
tag which contain "This is Stack overflow" . until the
tag which contain "This is stack overflow2".
is it possible to use jsoup because i am using it from java class.

Thanks In advance

Tim Tim

Not sure what exactly you are requesting, but this is a start:

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class JsoupTester {
    public static void main(String[] args) throws Exception {
        String html = "<P>This is Stack overflow</p>"
                + "<p>---------------</p>"
                + "<p>---------------</p>"
                + "<p>This is stack overflow2</p>";
        Document doc = Jsoup.parse(html);
        Elements elements ="p");

        for(Element e : elements) {

Now you can adapt the loop and add conditions, depending on what you want to include.

These links are helpful: