View Single Post
Old 05-7-2012, 07:47 AM   #26
SKG_Scintill
Spun a twirly fruitcake,
FFR Simfile AuthorFFR Veteran
 
SKG_Scintill's Avatar
 
Join Date: Feb 2009
Age: 31
Posts: 3,865
Default Re: [JAVA] Site Search Help

"You gave it a shot" wouldn't do, so I gave it another couple of shots.

I started with the code in the OP and expanded from that.
First thing I noticed is that the InputStreamReader read the entire code of the site. Every time the in.readLine() put something inside my inputLine it was one line further down the entire code.
So unless the word was in the first line of the site code (which is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"), it would refresh the site, instead of looking through the rest of the code.

There are two classes again.
This is the code that works for me and does what I want it to do:
Code:
import java.awt.*;
import java.awt.event.*;

public class Tabswitch {
	public static void main(String[] args) throws Exception{
		Robot r = new Robot();
		r.keyPress(KeyEvent.VK_ALT);
		r.keyPress(KeyEvent.VK_TAB);
		r.delay(100);
		r.keyRelease(KeyEvent.VK_ALT);
		r.keyRelease(KeyEvent.VK_TAB);
		URLReader a = new URLReader();
	}
}

--------------------------------------------------------------------------------------

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;

public class URLReader{
	public URLReader() throws Exception{
		URL site = new URL("http://kaction.com/badfanfiction/");
		BufferedReader in = new BufferedReader(
				new InputStreamReader(site.openStream()));
		
		String inputLine;
		while((inputLine = in.readLine()) != null){
			if(inputLine.contains("</b> and")){
				if(inputLine.contains("Final")){
					System.exit(0);
				}
			}
			if(inputLine.contains("</b>.")){
				if(inputLine.contains("Final")){
					System.exit(0);
				}
				else{
					Robot s = new Robot();
					Thread.sleep(2000);
					s.keyPress(KeyEvent.VK_F5);
					s.keyRelease(KeyEvent.VK_F5);
					Thread.sleep(2000);
					URLReader a = new URLReader();
				}
			}
		}
	}
}
It's probably a very unorthodox way of programming, but it's a way I could understand it myself.
__________________





Quote:
Originally Posted by bluguerilla
So Sexy Robotnik (SKG_Scintill) {.0001/10} [--]
___
. RHYTHMS PR LAYERING
. ZOMG I HAD TO QUIT OUT TERRIBLE
.

Last edited by SKG_Scintill; 05-7-2012 at 08:08 AM..
SKG_Scintill is offline   Reply With Quote