ruby - Check specific line of HTML in Java -
i have following ruby code checks www.usnwc.org see if biking/running trails open. specifically, checks image changes status of trails:
require 'open-uri' content = open('http://usnwc.org/#trail-status').read if content =~ /trailsclosed\.png/ puts "trails closed!" elsif content =~ /trailsopen\.png/ puts "trails open!" else puts "oops, images not found?" end
i perform same task in java. far have following code gets page , prints whole html file console.
public class openurl { /** * @param args command line arguments * @throws java.io.ioexception */ public static void main(string[] args) throws ioexception { url usnwc = new url("http://www.usnwc.org/#trail-status"); try (bufferedreader in = new bufferedreader(new inputstreamreader( usnwc.openstream()))) { string inputline; while((inputline = in.readline()) != null) system.out.println(inputline); } } }
how can check image present using java?
something this:
if (inputline.contains("trailsclosed.png")) { // trails closed }
similar check can made trailsopen.png.
once match found can break while loop.