import java.io.*;
import java.net.*;
public class UrlVisit {
/** Creates a new instance of UrlVisit */
public UrlVisit() {
}
public boolean visitWebPage(String UrlToVisit) {
boolean urlVisited = false;
try {
URL url = new URL(UrlToVisit);
URLConnection urlConnection = url.openConnection();
BufferedReader htmlPage = new BufferedReader(new
InputStreamReader(url.openStream()));
String line = "";
while((line = htmlPage.readLine()) != null) {
//do something with the html line
System.out.println(line);
}
htmlPage.close();
urlConnection = null;
urlVisited = true;
} catch(Exception e) {
urlVisited = false;
}
return urlVisited;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
UrlVisit urlVisit = new UrlVisit();
String url = null;
String commstart = " <!-- *********************** ";
String commend = " *********************** -->";
if (args[0] == null) {
url = "http://www.cnn.com";
} else {
url = args[0];
System.out.println(commstart + "Visiting "+ url + commend);
}
if (urlVisit.visitWebPage(url)) {
System.out.println(commstart + url + " visited" + commend);
} else {
System.out.println(commstart + url + " Website not found" +
commend);
}
}
}
"John" <no****@nospam.com> wrote in message
news:RM********************@magma.ca...
Some example working code:
http://www.javapractices.com/Topic147.cjp
dave wrote:
I am trying to open a url and read the data into a string.
for example,
I want to see the raw html within www.sourceforge.com put into a String.
Then I'll parse out the data I need.
thanks for any help.