Answer the question
In order to leave comments, you need to log in
How to get the content of a webpage in Java?
I want to get the content of a web page from a specific resource, for example, yandex.ru
Here's the code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.*;
public class pageFromSite {
public static void main(String[] args) throws Exception {
URL url = new URL("http://yandex.ru/");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openConnection().getInputStream(), "UTF-8"));
while (true) {
String line = reader.readLine();
if (line == null)
break;
System.out.println(line);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question