A
A
askalidov2022-03-26 21:38:24
Java
askalidov, 2022-03-26 21:38:24

How to parse data from localhost:8080 using Jsoup?

Is there such a possibility at all?
I have 10 containers with class="card", here is the code:

try {
      Document doc = Jsoup.connect("http://localhost:8080/configurator").get();
      Elements cards = doc.getElementsByAttributeValue("class", "card");
      System.out.println(cards.size());
} catch (IOException ex) {
    ex.printStackTrace();
}

According to my logic, it should output 10 to the console, but it displays 0. Accordingly, suspicions creep in that the code does not work very well :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2022-03-27
@askalidov

I looked at the source code of the project and everything fell into place.
First, this project uses Vaadin. Unfortunately, I haven't had a chance to use it, but I can say this:
Page content is rendered dynamically on the client. JSoup does not know how to work with dynamically generated content, and therefore, at the time of document parsing, there is only:
<div id="outlet"></div>
Accordingly, in order to parse dynamic content, you need to:
1) either study the internal API and parse the json that is returned from the outside. Go to the Network tab of your browser and filter the XHR requests and see which endpoint the request is made to and what is returned in response.
2) either parse the site using Selenium. (launch browser, wait for page to load, get document, get List<WebElement>)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question