I would like to find a piece of text inside the HTML of a web page, as fast as possible, I think my procedure is the worst, but do you have any tips?
My code is like this:
public static void main(String[] args) throws Exception
{
URL url = new URL("http://stackoverflow.com/");
BufferedReader in = new BufferedReader(
new InputStreamReader(url.openStream()));
String isPresent = "img";
boolean on = false;
String inputLine;
while ((inputLine = in.readLine()) != null)
{
if(inputLine.contains(isPresent)) on = true; //This takes a lot!!
}
}
Since web pages have a lot of lines of HTML code and since I have few experience with HTML, the if(inputLine.contains(isPresent))
line, takes lot of seconds to be executed sometimes. Do you think is there a more efficient way in terms of time, to improve that? Thank you.