简体   繁体   中英

How can I get data from a website with Java?

Hey I want to get a data from a Website. I had tried a lot but I dont get it.

This is the Website https://fortnitetracker.com/profile/psn/Julianpjp

I want the wins

My Code

public static void main(String[] args) throws Exception{
        final String url = "https://fortnitetracker.com/profile/psn/Julianpjp";
        final Document document = Jsoup.connect(url).get();

        for (Element row : document.select("div#profile")) {
            final String siege = row.select("trn_defstat_value").text();
            System.out.println(siege);

        }
    }

The is the value that I want

<div class="trn-defstat__value">5</div>

This are the higher element

<div id="profile" class="trn_profil>

select() expects a CSS selector. You're passing "trn_defstat_value" . This would select an element named trn_defstat_value :

<trn_defstat_value>...</trn_defstat_value>

You want to select the element which has a given CSS class . And the class is named trn-defstat__value , not trn_defstat_value . So the proper selector is thus ".trn-defstat__value" .

Note that you're iterating over all the divs with the ID "profile", but by definition of n ID, there can be only one. And you're not iterating through the elements with the class trn-defstat__value , but there are many of them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM