Forum Moderators: phranque

Message Too Old, No Replies

Scripting for a dynamic query request

Dynamic Query

         

neh2008

10:50 pm on Jan 12, 2003 (gmt 0)

10+ Year Member



Hi Folks,

I need some hint for a small programming project?

I want to write a PHP or JSP script which will run a query which is much like ...

[google.com...]

I will be feeding a variety of things to it (e.g "nehal" in this case)to the script from time to time. But, I do not know how to get the response and SAVE it as a separate HTML Document everytime with a new name and with all the images and stuff in it.

Please help, it could lead me to a full-time job.

It sounds much like a spider, but my spider will spider only my site. limited...

Thanks.
-nehal

bcc1234

1:10 am on Jan 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check java.net.URL and java.net.URLConnetcion classes.
About saving the data into a file - just append a timestamp and a random variable for a file name.

Something like:

String fileName=new StringBuffer("/mypath/").append(System.currentTimeMillis()).append((int)(Math.random()*99)).toString();

neh2008

2:35 am on Jan 13, 2003 (gmt 0)

10+ Year Member



I think using the URL Class, I can generate the Queries.

But then, how would I save the response of that Query generated by the URL I produce?

IS it like this?

1. I pass the URL to a class which will in turn open a connection to the net using the URL and that's how I will go to that page.

2. After I am on that page, my class' method can save the Response as a file.

Am I on a right direction?

Please help.

bcc1234

2:55 am on Jan 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use openStream() method and read all input that you get and store it in a file. That's the easiest way I can think of.

neh2008

3:48 am on Jan 13, 2003 (gmt 0)

10+ Year Member



But then, Do I have to say that "Open a Connection on port 80" or "look for "HTTP" content?

Or it understands that by itself?

I am doing the program in parallel to waiting for reply to this thread. I should be good in you guys' company.

Thank you ..

neh2008

4:05 am on Jan 13, 2003 (gmt 0)

10+ Year Member



Here is my little test code.....

I was online when I run the code ...didn't get anything in the file...

:(

import java.net.*;
import java.io.*;

public class Url {
public static void main(String[] argv){
BufferedInputStream text= null;

URLConnection conn = null;
PrintWriter fout = null;

try{

URL url = new URL("http://WWW.YAHOO.COM/");
try{

text = new BufferedInputStream(url.openStream());
fout= new PrintWriter(new FileWriter("SS1.html"));
fout.println( "------------------------" );
fout.println(text);
fout.println( "------------------------" );

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

}
}

neh2008

11:20 pm on Jan 13, 2003 (gmt 0)

10+ Year Member



OK!

Finally, I got it to work for me.

Thank you.

-Nehal