我正在用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抓取的语法。
感谢您的帮助!
答案 0 :(得分:0)
尝试改用此行:
Elements players = page.select(".playerName");