解析网站以返回玩家名单的Java代码不会返回任何内容

时间:2019-04-25 23:20:36

标签: java html jsoup

我正在用Java编写一个程序,该程序将浏览网站的html数据,找到某个文本值,然后将其返回给我。我非常不熟悉HTML。这是我到目前为止依靠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());
             }
    }

我要寻找的课程在网站的结构中

<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>

我不确定它是否打印出播放器的名称,因为它被埋在更多类中,或者我是否弄乱了Jsoup抓取的语法。

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试改用此行:

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