I'm currently retrieving HTML from a forums page using this code
String html = null;
URLConnection connection = null;
try {
connection = new URL(forumsURL).openConnection();
connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36");
Scanner scanner = new Scanner(connection.getInputStream());
scanner.useDelimiter("\\Z");
html = scanner.next();
scanner.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Issues communicating with forums");
return;
}
This code had been working for me for years. However, now when it retrieves the HTML, some of the string text values are being replaced with "-".
The HTML I'm parsing looks like this when I view it on the webpage:
<div style class="onlineInfo">
<span class="PlayersOnline">20</span>
"/"
<span class="MaxPlayers">50</span>
</div>
But the HTML my code is returning looks like this:
<div style="display:none" class="onlineInfo">
<span class="PlayersOnline">-</span>/<span class="MaxPlayers">50</span>
</div>
Notice that the "PlayerOnline" value is being replaced, no longer showing player count, but instead just returning "-".
I'm not sure what has changed that would cause this to break. Any suggestions would be greatly appreciated.