Results 1 to 3 of 3
  1. #1
    stephanehk is offline Member
    Join Date
    Sep 2016
    Rep Power

    Default Parsing Google News RSS Not Working

    I am trying to parse this simple google RSS feed using java. My goal is to get all the titles of the news articles. My code below, however, does not do this. I would really appreciate your help, thanks.

    Link: http://

    Parsing Method:

    Java Code:
    public static String readLink(String urlAdress) throws IOException {
         int i = 0;
         URL rssUrl = null;
         try {
         rssUrl = new URL(urlAdress);
         } catch (MalformedURLException e2) {
         // TODO Auto-generated catch block
         BufferedReader in = null;
         try {
         in = new BufferedReader(new InputStreamReader(rssUrl.openStream()));
         } catch (IOException e1) {
         // TODO Auto-generated catch block
         String articleTitles = "";
         String line = in.readLine();
         while (line != null) {
             i ++;
             System.out.println("Line is not null");
         if (line.contains("<title>")) {
             System.out.println("Found <title>");
         int firstPos = line.indexOf("<title>");
         String temp = line.substring(firstPos);
         temp = temp.replace("<title>", "");
         int lastPos = temp.indexOf("</title>");
         temp = temp.substring(0, lastPos);
         articleTitles += temp + "\n";
         if (i > 6) {
         try {
         } catch (IOException e) {
         // TODO Auto-generated catch block
         return articleTitles;
    The Output:
    Java Code:
    Text: technology - Google News
    technology - Google News
    technology - Google News
    technology - Google News
    technology - Google News
    technology - Google News
    technology - Google News
    *Just by the way I simply call the method with this line:

    Java Code:
    System.out.print("Text: " + readLink("" + word + "&output=rss"));

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Parsing Google News RSS Not Working

    however, does not do this
    Please explain what the code does do and add some comments saying what is wrong with that
    and show what the program's output should be.

    Note: The posted code is poorly formatted with missing indentations. Please fix the code so that it is readable.

    Also please add some comments describing what the input line looks like
    and what the code is trying to extract from that line.
    Last edited by Norm; 09-21-2016 at 03:18 AM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Parsing Google News RSS Not Working

    I don't (offhand) see anywhere that would produce that output.
    I'll echo Norm's request about formatting the code properly.

    A quick scan of the code, though, shows some issues.
    You have a couple of try/catch blocks that you continue to process things even if there's already been an error.
    For example, when getting the BufferedReader if there's an exception you don't exit, you just keep going, which will invariably result in a NullPointerException.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 10
    Last Post: 11-23-2013, 06:47 PM
  2. Applet not working in Google Chrome
    By ernstlenzer in forum Java Applets
    Replies: 3
    Last Post: 06-12-2012, 01:41 AM
  3. Java Applet is not working in Google Chrome
    By AsoInfo in forum Java Applets
    Replies: 2
    Last Post: 01-28-2012, 05:56 AM
  4. Replies: 8
    Last Post: 05-28-2008, 07:00 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts