I want to download the html source code of a site to parse some info. How do I accomplish this in Java?
Just attach a BufferedReader (or anything that reads strings) from a URL's InputStream returned from openStream().
public static void main(String[] args)
throws IOException
{
URL url = new URL("http://stackoverflow.com/");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String s = null;
while ((s = reader.readLine()) != null)
System.out.println(s);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With