0

I have a problem the Jsoup is not selecting the div and shows nothingI have no error but it shows nothing

private void getWebsite() {
    Document doc = null;

    try {
        doc = Jsoup.connect("http://test.com/test.html").get();
        Elements text = doc.select("div[id=content]");
        System.out.println(text);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Pshemo
  • 122,468
  • 25
  • 185
  • 269
Marvin99
  • 1
  • 1
  • 2
    Need to see your HTML. At least part of it. – TDG Mar 29 '17 at 18:23
  • To update your question with more info use [edit] option. Currently we can't say why your code doesn't work since we can't reproduce this problem. To get better help post [MCVE] (a.k.a. [SSCCE](http://sscce.org)) – Pshemo Mar 30 '17 at 17:13
  • If `doc.select("div[id=content]").text()` returns empty string, it suggests that either there is no div with such id in response which you got, of that this div doesn't hold any text node. Possibly you just got some basic HTML frame and script which your browser should execute to fill it with more elements dynamically (via JavaScript). In that case jsoup will not help you since it is simple parser not browser emulator so it doesn't emulate JavaScript. Take a look at http://stackoverflow.com/a/7344305 – Pshemo Mar 30 '17 at 20:04

1 Answers1

-1

Try

Elements text = doc.select("div#content"); (or)
Element text = doc.getElementById("context");
AG_
  • 54
  • 3
  • Any specific reason why you think that `select("div#content")` should work even if `select("div[id=content]")` failed? – Pshemo Mar 30 '17 at 19:51