简体   繁体   English

从网页上读取数据

[英]Read data from webpage

I am trying to read data from the given web page using Java. 我试图使用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? 从网页上获取日期的正确方法是什么?

You must be having proxy or firewall set. 您必须设置代理或防火墙。 This code works. 这段代码有效。

You are probably behind a proxy that doesn't allow you to connect to a web resource through a java application. 您可能在代理之后,不允许您通过Java应用程序连接到Web资源。 You can configure a proxy in the java options. 您可以在java选项中配置代理。 In Windows you can do that from the Control Panel. 在Windows中,您可以从“控制面板”执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM