Saket Sinha Saket Sinha - 1 year ago 81
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
Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download