Search code examples
javahtmljsoup

Java code that parses a website to return a llist of players does not return anything


I am writing a program in java that will look through a website's html data, find a certain text value, and then return that to me. I am very unfamiliar with working with HTML. Here is the code I have so far, relying on Jsoup.

public static void getPlayerData() throws IOException
    {
        Document page = Jsoup.connect("theURL").get();
        String title = page.title();
        Elements players = page.getElementsByClass("playerName playerNameNoHealth");
        for (Element span : players)
             {
                System.out.println(span.text());
             }
    }

The class that I have it looking for is here in the website's structure

<body class="">
<div id-"mcmap" class="dynmap">
<div class ="map leaflet-container leaflet-fade-anim">
<div class ="leaflet-map-pane">
<div class ="leaflet-objects-pane">
<div class ="leaflet-marker-pane">
    <div class="Marker playerMarker leaflet-marker-icon leaflet-clickable"style="transform: translate3d(281px, 75px, 0px); z-index: 75;">
        <img class="playerIcon" src="tiles/faces/32x32/(The player's name)"">
        <span class="playerName playerNameNoHealth">(Player's name)</span>

I'm not sure if it is not printing the Player's name because it is buried inside more classes, or if I have messed up the syntax for the Jsoup scraping.

Any Help is appreciated!


Solution

  • Try using this line instead:

    Elements players = page.select(".playerName");