简体   繁体   English

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

[英]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. 我正在用java编写一个程序,它将查看网站的html数据,查找某个文本值,然后将其返回给我。 I am very unfamiliar with working with HTML. 我对使用HTML非常不熟悉。 Here is the code I have so far, relying on Jsoup. 这是我到目前为止的代码,依赖于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. 我不确定它是不是打印播放器的名称,因为它被隐藏在更多类中,或者如果我搞砸了Jsoup抓取的语法。

Any Help is appreciated! 任何帮助表示赞赏!

请尝试使用此行:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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