Question:
How do I make a java file search a web page?
MJ
2010-10-25 07:34:30 UTC
I'm playing around with Java and seeing if I could make a file search an online document for keywords. My current code has it searching a text file, but I would like to see if I could apply this to something more useful. I do not wish for completely modified code, but maybe a suggestion on what I can do/add to do this. I'll place my code in here for reference though.

My code is simple:

public class readFile {

public static void main(String[] args) {


Scanner scan = new Scanner(System.in);
String iPut;
System.out.println ("Keyword:");
iPut = scan.nextLine();
iPut = iPut.toLowerCase();
int i = 0;

try
{
FileInputStream in = new FileInputStream("fileToRead.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String strClone;

while((strLine = br.readLine())!= null)
{
i++;
strClone = strLine.toLowerCase();
if (strClone.contains(iPut)){
System.out.println("Line: " + i + ": " + strLine);}
else{}

}

}catch(Exception e){
System.out.println(e);
}

}
}
Three answers:
deonejuan
2010-10-25 08:28:22 UTC
We call that genre of code 'agents' or 'bots' if it returns a specific. Or we call it a spyder if it goes around seeking changes. Link below has code for an Amazon.com retrieval. The problem is, more and more, that web pages are not static and they do not show the page source which you must have in order to search keywords.
Yahoo Jedi
2010-10-25 07:41:55 UTC
* Grab the web page; it returns a text

* Search the text for the string you are looking for

* Output results
RS
2010-10-25 07:44:34 UTC
What You are Actually trying to REDO is Making you own WEB BROWSER That's it!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...