Hi everyone,

Could some one please tell me or show me the entire codings of how to insert a string to a thml code....like: to "http://www.google.co.uk/" i want to search a string and get the source code of the page result,and one more thing: how can i found a specified string or number at the back-readed html code...

Thank You

Yours Sincerely

Akos Molnar

Hi,

You can fetch the html page by using the URL class, and then parse the resulting html as you would do with a normal file:

URL url = new URL("http://www.google.co.uk/q=daniweb");
 InputStream is = url.openStream();

One you got the stream, you can read it into a string :

byte[] buffer = new byte[512];
   int c=0;
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   while( (c = is.read(buffer)) > -1){
       baos.write(buffer, 0, c);
   }
   is.close();
   String html = baos.toString();

And then search the string for what you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.