从网页读取数据 [英] Read data from webpage
本文介绍了从网页读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Java从给定的网页中读取数据.
I am trying to read data from the given web page using Java.
public class WebpageReader {
public static void main(String[] args) throws IOException {
String line = null, response;
URL url = new URL("http://www.google.co.in/");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn
.getInputStream()));
while (rd.readLine() != null) {
line += rd.readLine();
}
System.out.println(line);
}
}
但是我收到连接被拒绝的异常.从网页获取日期的正确方法是什么?
But I'm getting the connection refused exception. What might be correct way to get the date from webpage?
推荐答案
您可能位于不允许您通过Java应用程序连接到Web资源的代理后面.您可以在java选项中配置代理.在Windows中,您可以从控制面板"中执行此操作.
You are probably behind a proxy that doesn't allow you to connect to a web resource through a java application. You can configure a proxy in the java options. In Windows you can do that from the Control Panel.
这篇关于从网页读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文