Jump to content

Recommended Posts

Posted

Hello once again,

im sure you know some programms out there that actually leech site's html codes.

So that's what ive made, but it only takes the html code from the url u have entered and saves it to the file requested not the images.

package com.test;

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

/**
* @author Voqus
*/
public class HTMLeech {
public static void main(String args[]) {
	try {
		URL url = new URL("http://www.google.gr");
		// Read the text returned from the site
		BufferedReader br = new BufferedReader(new InputStreamReader(
				url.openStream()));
		String htmlcode;
		while ((htmlcode = br.readLine()) != null) {
			try {
				FileWriter fw = new FileWriter("HTMCode.txt");
				BufferedWriter bw = new BufferedWriter(fw);
				while ((htmlcode = br.readLine()) != null) {
					bw.write(htmlcode + "\n");
				}
				bw.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		br.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
}

Screen:

H5Pz7.png

LKIde.png

Tadaaaa!

Credits: Me

Posted

You could of just done that. Every byte in that input stream is a char, your case is the worst case to use a buffer reader.

 

*Sigh*, you only needed 1 output stream writer not two >.>

		URL url = new URL("http://www.google.gr");
		InputStream io = url.openStream();
		byte[] data = new byte[io.available()];
		io.read(data);

		String result = new String(data);

Posted

			URL url = new URL("http://www.google.gr");
		InputStream io = url.openStream();
		byte[] data = new byte[io.available()];
		io.read(data);

		String result = new String(data);
                        System.out.println(result);

Well yea that's true but ur code just prints out on the console not creating a file and write it.

Anyway thx.

 

Posted

			URL url = new URL("http://www.google.gr");
		InputStream io = url.openStream();
		byte[] data = new byte[io.available()];
		io.read(data);

		String result = new String(data);
                        System.out.println(result);

Well yea that's true but ur code just prints out on the console not creating a file and write it.

Anyway thx.

 

I gave  you the string, then you can write it.

 

Take a look:

	URL url = new URL("http://www.google.gr");
	InputStream io = url.openStream();

	byte[] data = new byte[io.available()];
	io.read(data);

	FileOutputStream fs = new FileOutputStream(new File("index.html"));
	fs.write(data);
	fs.flush();

 

Later edit: Btw, i didn't see you use flush in your out stream writers, you always have to flush the data out after writing something in the stream, that's what saves it on your disk :)

 

Also buffer reader is used only when you wanna get a collection of strings, or parse an csv file, and so forth. And in a text file every byte in there is a char.

 

And finally the way a buffer reader is needed to eb set up is like this:

	BufferedReader br = new BufferedReader(new InputStreamReader(io));

	while(br.ready()) {
		String line = br.readLine();
	}

It's exactly like in l2js db connections, "while(rs.next);";

 

Hope it helps :)

Posted

I gave  you the string, then you can write it.

 

Take a look:

	URL url = new URL("http://www.google.gr");
	InputStream io = url.openStream();

	byte[] data = new byte[io.available()];
	io.read(data);

	FileOutputStream fs = new FileOutputStream(new File("index.html"));
	fs.write(data);
	fs.flush();

 

Later edit: Btw, i didn't see you use flush in your out stream writers, you always have to flush the data out after writing something in the stream, that's what saves it on your disk :)

 

Also buffer reader is used only when you wanna get a collection of strings, or parse an csv file, and so forth. And in a text file every byte in there is a char.

 

And finally the way a buffer reader is needed to eb set up is like this:

	BufferedReader br = new BufferedReader(new InputStreamReader(io));

	while(br.ready()) {
		String line = br.readLine();
	}

It's exactly like in l2js db connections, "while(rs.next);";

 

Hope it helps :)

aham yep, i can see it now thanks  ;D.

Btw i'm not really into l2j crap so dont tell about how they use trove and stuff  ::)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...