C
C
ceramicthree2020-05-07 00:37:18
Java
ceramicthree, 2020-05-07 00:37:18

Why can't I parse this value via Jsoup?

I want to parse the value of those infected with a virus. 5eb32d69b01b8310317241.png
I tried to access div.today__item__value, I also tried starting from article#free-research.free-researchgetting to the desired number of infections, but, unfortunately, nothing could be output to the console. Could you tell me how to parse such values?
Now the code looks like this:

package examples;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import java.io.IOException;

public class YandexCovid {
    public static String infoParse(){
        StringBuilder covidInfo = new StringBuilder();
        try {
            Document document = Jsoup.connect("https://yandex.ru/covid19/stat").get();
            Elements elements = document.getElementsByClass("today__item__value");

            covidInfo.append(elements.text());
        }catch (IOException e){
            e.printStackTrace();
        }
        return covidInfo.toString();
    }

    public static void main(String[] args){
        System.out.println(YandexCovid.infoParse());
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2020-05-07
@ceramicthree

Good afternoon!
1) What you see in the browser console (when inspecting elements) and what is displayed in the source code ctrl + u differ.
These elements are not in the source code, as they are supposedly added to the DOM dynamically (using js). Looks like the react framework.
Accordingly, parsing with the help of jsoup will not work.
Look towards
selenium + jbrowserdriver - https://github.com/MachinePublishers/jBrowserDriver
selenium + chrome || firefox

A
Andrey_Dolg, 2020-05-07
@Andrey_Dolg

It is highly likely that the data comes in one of the requests. Study the requests that the page receives when it loads.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question