简体   繁体   中英

Extracting data from HTML page using Jsoup

I'm trying to get my level of each skill from https://secure.runescape.com/m=hiscore_oldschool/hiscorepersonal.ws?user1=Feed%20Meh%20Dog

It's a table but I don't see a table id anywhere. I just need to know what id or class I should be using.

Tried multiple tutorials, but all have a straight forward table class or id. There is a div ID which I think I should use, just not sure how to extract each specific row/skill.

final Document document = Jsoup.connect(" https://secure.runescape.com/m=hiscore_oldschool/hiscorepersonal.ws?user1=Feed%20Meh%20Dog ").get();

    for (Element row : document.select("WHAT DO I PUT HERE tr")); {
        final String Attack = row.select("WHAT DO I PUT HERE")
        final String Defence = row.select("WHAT DO I PUT HERE")
        final String Strength = row.select("WHAT DO I PUT HERE")
    }

Just want to output the row, or individual skills to the console. Any help would be much much appreciated.

I would recommend using the official API if you want to get the data you're looking for easily. Using this link: https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player= To do that with Jsoup in a hacky kind of way would look a little like this...

    final Document document = Jsoup.connect("https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=Feed%20Meh%20Dog").get();
    final Element body = document.selectFirst("body");

    String[] rawSkills = body.html().split(" ");
    ArrayList<String[]> skills = new ArrayList<>();

    for(String s: rawSkills ) {
        skills.add(s.split(","));
    }

    System.out.println(skills.get(0)[1]);

Then to select an individual skill, you would do something like skills.get(x)[y] with x being the index in the array the skill is (starting 0) and y being which piece of information from the skill you want. 0 being rank, 1 being skill level and 2 being xp.

The API doesn't provide names of each skill so you would have to do that manually. The skill order is as it is on the high scores page here .

EDIT: I've taken the liberty to create a small Java wrapper for this specific endpoint which you can find here .

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