Skip to Main Content

Not able to run a program to extract news from news channel websites.

1035500Sep 2 2013 — edited Sep 11 2013

Let me start with stating the fact that I am a super greenhorn, so please be ultra elaborate with the answers .
This is my code, I copied it from Mr. Alvin Alexander (http://alvinalexander.com/java/edu/pj/pj010011?). I am trying to use it to extract news from news channel websites.

I used the following URLs:

1.http://in.reuters.com/

2.http://timesofindia.indiatimes.com/

3.http://www.hindustantimes.com/

//------------------------------------------------------------//

// JavaGetUrl.java: //

//------------------------------------------------------------//

// A Java program that demonstrates a procedure that can be //

// used to download the contents of a specified URL. //

//------------------------------------------------------------//

// Code created by Developer's Daily //

//  http://www.DevDaily.com  //

//------------------------------------------------------------//

import java.io.*;

import java.net.*;

public class JavaGetUrl {

  public static void main (String[] args) {

  //-----------------------------------------------------//

  // Step 1: Start creating a few objects we'll need.

  //-----------------------------------------------------//

  URL u;

  InputStream is = null;

  DataInputStream dis;

  String s;

  try {

  //------------------------------------------------------------//

  // Step 2: Create the URL. //

  //------------------------------------------------------------//

  // Note: Put your real URL here, or better yet, read it as a //

  // command-line arg, or read it from a file. //

  //------------------------------------------------------------//

  u = new URL("http://200.210.220.1:8080/index.html");

  //----------------------------------------------//

  // Step 3: Open an input stream from the url. //

  //----------------------------------------------//

  is = u.openStream(); // throws an IOException

  //-------------------------------------------------------------//

  // Step 4: //

  //-------------------------------------------------------------//

  // Convert the InputStream to a buffered DataInputStream. //

  // Buffering the stream makes the reading faster; the //

  // readLine() method of the DataInputStream makes the reading //

  // easier. //

  //-------------------------------------------------------------//

  dis = new DataInputStream(new BufferedInputStream(is));

  //------------------------------------------------------------//

  // Step 5: //

  //------------------------------------------------------------//

  // Now just read each record of the input stream, and print //

  // it out. Note that it's assumed that this problem is run //

  // from a command-line, not from an application or applet. //

  //------------------------------------------------------------//

  while ((s = dis.readLine()) != null) {

  System.out.println(s);

  }

  } catch (MalformedURLException mue) {

  System.out.println("Ouch - a MalformedURLException happened.");

  mue.printStackTrace();

  System.exit(1);

  } catch (IOException ioe) {

  System.out.println("Oops- an IOException happened.");

  ioe.printStackTrace();

  System.exit(1);

  } finally {

  //---------------------------------//

  // Step 6: Close the InputStream //

  //---------------------------------//

  try {

  is.close();

  } catch (IOException ioe) {

  // just going to ignore this one

  }

  } // end of 'finally' clause

  } // end of main

} // end of class definition

This is the error i am getting, every time I run it on Eclipse:

Oops- an IOException happened.

java.net.ConnectException: Connection refused: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method)

  at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)

  at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)

  at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)

  at java.net.AbstractPlainSocketImpl.connect(Unknown Source)

  at java.net.PlainSocketImpl.connect(Unknown Source)

  at java.net.SocksSocketImpl.connect(Unknown Source)

  at java.net.Socket.connect(Unknown Source)

  at java.net.Socket.connect(Unknown Source)

  at sun.net.NetworkClient.doConnect(Unknown Source)

  at sun.net.www.http.HttpClient.openServer(Unknown Source)

  at sun.net.www.http.HttpClient.openServer(Unknown Source)

  at sun.net.www.http.HttpClient.<init>(Unknown Source)

  at sun.net.www.http.HttpClient.New(Unknown Source)

  at sun.net.www.http.HttpClient.New(Unknown Source)

  at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)

  at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)

  at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)

  at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)

  at java.net.URL.openStream(Unknown Source)

  at JavaGetUrl.main(JavaGetUrl.java:33)

.

.

.

.

.

Also, when I try a local server URL, the output screen goes blank, which I guess is due to lack of Text on the local URL. So, the little research that I did, made me believe that the code not running on external server was due to firewall on the server side. Please help me run it. Also : I work on a proxy network.( if that has something to do with this).

P.S : Advanced gratitude for any assistance.

Comments
Post Details
Added on Sep 2 2013
1 comment
1,195 views